Google map nearbySearch Incorrect number of records

When I executed this(https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=6.9119022,79.8553512&radius=5000&type=atm&key=) request for 5000m radius, we can obtains 60 records, when using next_page_token for subsequent requests.
https://maps.googleapis.com/maps/api/place/nearbysearch/json?pagetoken=&key=

But when I excecuted request with radius=50000, we can obtains only 38 records.

Same behavior when using JavaScript library also.

I would appreciate any help. Thanks


Source: stackoverflow-javascript

PHP/Mysql store location service with only country and zip code data

I have a database that contains the country and zip code of a list of stores. I have to build a simple page that allows a person to input the zip code and country, then a map will show the closest locations to the zip/country info they input.

For example if they enter USA/90210, the map would show all the stores closest to that location.

I was looking at the google maps API php/mysql example but it requires lat/long data.

https://developers.google.com/maps/documentation/javascript/store-locator

Any ideas how to do this with just a database that contains zipcode and country?


Source: stackoverflow-php

InvalidValueError: initMap is not a function, Google MAP doesn’t show in webpage

using PHP & MYSQL on WordPress and Google Map API in order to retrieve data from MYSQL database and display markers with info windows on Google Map.

problem is that the map doesn’t appear on the webpage, yet the SQL query is retrieving the required data.

where i have 2 SQL queries:

  • first one that retrieve data and display it in table
  • second one that retrieve the selected data from the first query and
    display the markers on the Google Map API

after the user click on the button and select its input the system must display the table that contains the data and the Google MAP must be displayed with the markers above this table.

the problem is that when i tried to click the submit button the browser display in the console :

InvalidValueError: initMap is not a function

without displaying the Google MAP

code:

     <?php
        /*
        Template Name: search info_location
        */

        get_header();
          ?>

<!DOCTYPE html>
<html>
  <head>
    <title>Custom Markers</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    https://maps.googleapis.com/maps/api/js?key=AIzaSyCquey2tCZ32jLJJDEEi2D7_RnXXyj9RTI&callback=initMap
     <style>
      /* Always set the map height explicitly to define the size of the div
       * element that contains the map. */
      #map {
        height: 200px;
      }
      /* Optional: Makes the sample page fill the window. */
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
    </style>

  </head>
  <body>
    
<?php // code for submit button action global $wpdb, $site_name; //variables that handle the retrieved data from mysql database based on the ID of the variable in HTML (select) if(isset($_POST['query_submit'])) { if(isset($_POST['site_name'])) { $site_name=$_POST['site_name']; } else { $site_name=""; } if(isset($_POST['owner_name'])) { $owner_name=$_POST['owner_name']; } else { $owner_name=""; } if(isset($_POST['Company_name'])) { $company_name=$_POST['Company_name']; } else { $company_name=""; } if(isset($_POST['Subcontractor_name'])) { $Subcontractor_name=$_POST['Subcontractor_name']; } else { $Subcontractor_name="";} // var_dump($site_name); $sql = $wpdb->prepare("select i.siteID , i.siteNAME , i.equipmentTYPE , c.latitude , c.longitude , c.height , o.ownerNAME , o.ownerCONTACT , x.companyNAME , y.subcontractorCOMPANY , y.subcontractorNAME , y.subcontractorCONTACT from site_info i LEFT JOIN owner_info o on i.ownerID = o.ownerID LEFT JOIN company_info x on i.companyID = x.companyID LEFT JOIN subcontractor_info y on i.subcontractorID = y.subcontractorID LEFT JOIN site_coordinates2 c on i.siteID=c.siteID where i.siteNAME = %s AND o.ownerNAME = %s AND x.companyNAME = %s ",$site_name,$owner_name,$company_name); $query_submit =$wpdb->get_results($sql, OBJECT); echo "<br>"; echo "<br>"; //echo $sql; // var_dump($_POST['site_name']); foreach ($query_submit as $obj) { $obj->siteNAME; $obj->ownerNAME; $obj->companyNAME; $obj->subcontractorNAME; $obj->siteID; $obj->equipmentTYPE; $obj->latitude; $obj->longitude; $obj->height; $obj->ownerCONTACT; $obj->subcontractorCONTACT; $obj->subcontractorCOMPANY; } // table that will dsiplay the results based on the user's selection // echo "<table width='30%' "; echo "<tr>"; echo "<td>Site Name</td>"; echo "<td>Owner Name</td>"; echo "<td>Company Name</td>"; echo "<td>Subcontractor Name</td>"; echo "<td>Site ID</td>"; echo "<td>Equipment Type</td>"; echo "<td> Lattitude</td>"; echo "<td>Longitude </td>"; echo "<td> Height</td>"; echo "<td> Owner Contact</td>"; echo "<td> Sub Contact</td>"; echo "<td> Sub company Name</td>"; echo "</tr>"; echo "<tr>"; echo "<td>".$obj->siteNAME."</td>"; echo "<td>".$obj->ownerNAME."</td>"; echo "<td>".$obj->companyNAME."</td>"; echo "<td>".$obj->subcontractorNAME."</td>"; echo "<td>".$obj->siteID."</td>"; echo "<td>".$obj->equipmentTYPE."</td>"; echo "<td>".$obj->latitude."</td>"; echo "<td>".$obj->longitude."</td>"; echo "<td>".$obj->height."</td>"; echo "<td>".$obj->ownerCONTACT."</td>"; echo "<td>".$obj->subcontractorCONTACT."</td>"; echo "<td>".$obj->subcontractorCOMPANY."</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; ?> var map,currentPopup; function initMap() { map = new google.maps.Map(document.getElementById('map'), { zoom: 8, center: new google.maps.LatLng(33.888630, 35.495480), mapTypeId: 'roadmap' }); var iconBase = 'https://maps.google.com/mapfiles/kml/shapes/'; var icons = { parking: { icon: iconBase + 'parking_lot_maps.png' }, library: { icon: iconBase + 'library_maps.png' }, info: { icon: iconBase + 'info-i_maps.png' } }; function addMarker(feature) { var marker = new google.maps.Marker({ position: feature.position, //icon: icons[feature.type].icon, map: map }); var popup = new google.maps.InfoWindow({ content: 'Site ID : ' + feature.info +'
' + ' Site Name' + feature.site_name +'
' + 'Coordinates : '+ feature.position +'
' + 'height : ' + feature.height, maxWidth: 300 }); google.maps.event.addListener(marker, "click", function() { if (currentPopup != null) { currentPopup.close(); currentPopup = null; } popup.open(map, marker); currentPopup = popup; }); google.maps.event.addListener(popup, "closeclick", function() { map.panTo(center); currentPopup = null; }); } var features = [ get_results("select c.siteID, c.latitude, c.longitude, c.height , i.siteNAME FROM site_coordinates2 c LEFT JOIN site_info i on c.siteID = i.siteID where i.siteNAME = '".$site_name."'", OBJECT) as $key => $row) { $latitude = $row->latitude; $longitude = $row->longitude; $siteid = $row->siteID; $height = $row->height; $siteName = $row->siteNAME; echo $prependStr; ?> { position: new google.maps.LatLng(, ), info:'', height: '', site_name: ', } ]; for (var i = 0, feature; feature = features[i]; i++) { addMarker(feature); } } <?php echo "</td>"; echo "</tr>"; echo "</table>"; } ?> <!-- the below part of code work as it should --!> <!--create dropdown list site names--> <form method ="post" action ="" name="submit_form"> <table width="30%"> <tr> <td>Site Name</td> <td>Owner Name</td> <td>Company Name</td> <td>Subcontractor Name</td> </tr> <tr> <td><select id="site_name" name = "site_name"> <?php $query_site_name =$wpdb->get_results("select DISTINCT siteNAME from site_info"); foreach($query_site_name as $site_name) { // $site_name = (array)$site_name; echo "<option value = '".$site_name ->siteNAME."'>". $site_name->siteNAME."</option>"; } ?> <!--create dropdown list owner names--> </select></td> <td><select id="owner_name" name ="owner_name"> <?php global $owner_name; $query_owner_name =$wpdb->get_results ("select DISTINCT ownerNAME from owner_info"); foreach($query_owner_name as $owner_name) { // $owner_name = (array)$owner_name; echo "<option value = '".$owner_name->ownerNAME."'>". $owner_name->ownerNAME."</option>"; } ?> </select></td> <!--create dropdown list Company names--> </select></td> <td><select id="Company_name" name ="Company_name"> <?php global $Company_name; $query_Company_name =$wpdb->get_results ("select DISTINCT companyNAME from company_info"); foreach($query_Company_name as $Company_name) { // $Company_name = (array)$Company_name; echo "<option value = '".$Company_name->companyNAME."'>". $Company_name->companyNAME."</option>"; } ?> </select></td> <!--create dropdown list Subcontractor names--> </select></td> <td><select id="Subcontractor_name" name ="Subcontractor_name"> <?php global $Subcontractor_name; $query_Subcontractor_name =$wpdb->get_results ("select DISTINCT subcontractorNAME from subcontractor_info"); foreach($query_Subcontractor_name as $Subcontractor_name) { // $Subcontractor_name = (array)$Subcontractor_name; echo "<option value = '".$Subcontractor_name->subcontractorNAME."}'>". $Subcontractor_name->subcontractorNAME."</option>"; } ?> </select></td> <tr> <td></td> <td></td> <td></td> <td></td> <td> <input type ="submit" name="query_submit" value ="Search" /> </td> </tr> </table> </form> </body> </html> <?php get_footer(); ?>

what am i doing wrong and how to fix this Problem.


Source: stackoverflow-javascript

Heatmap google map error with the array

I`m new with google maps y JS, and I have this problem.

this is my code:

var map, heatmap, data, position;

function initMap() {
  map = new google.maps.Map(document.getElementById('map'), {
    zoom: 13,
    center: {lat: 37.775, lng: -122.434},
    mapTypeId: google.maps.MapTypeId.SATELLITE
  });

  heatmap = new google.maps.visualization.HeatmapLayer({
    data: makeRequest('jsonmapasenal.php', function(data) {

         data = JSON.parse(data.responseText);
         data2 = [], range = data.length;
        for (i = 0; i < data.length; i++) {


             data2[i]= new google.maps.LatLng(parseFloat(data[i].lat), parseFloat(data[i].lon));  ---------Here is the problem
        }


    console.log(data2);
    return data2;
    }),
    map: map
  });
}

function toggleHeatmap() {
  heatmap.setMap(heatmap.getMap() ? null : map);
}

function changeGradient() {
  var gradient = [
    'rgba(0, 255, 255, 0)',
    'rgba(0, 255, 255, 1)',
    'rgba(0, 191, 255, 1)',
    'rgba(0, 127, 255, 1)',
    'rgba(0, 63, 255, 1)',
    'rgba(0, 0, 255, 1)',
    'rgba(0, 0, 223, 1)',
    'rgba(0, 0, 191, 1)',
    'rgba(0, 0, 159, 1)',
    'rgba(0, 0, 127, 1)',
    'rgba(63, 0, 91, 1)',
    'rgba(127, 0, 63, 1)',
    'rgba(191, 0, 31, 1)',
    'rgba(255, 0, 0, 1)'
  ]
  heatmap.set('gradient', heatmap.get('gradient') ? null : gradient);
}

function changeRadius() {
  heatmap.set('radius', heatmap.get('radius') ? null : 20);
}

function changeOpacity() {
  heatmap.set('opacity', heatmap.get('opacity') ? null : 0.2);
}

 function makeRequest(url, callback) {
    var request;

    if (window.XMLHttpRequest) {
        request = new XMLHttpRequest(); // IE7+, Firefox, Chrome, Opera, Safari

    } else {
        request = new ActiveXObject("Microsoft.XMLHTTP"); // IE6, IE5

    }
    request.onreadystatechange = function() {
        if (request.readyState == 4 && request.status == 200) {
            callback(request);

        }
    }
   request.open("GET", url, true);

    request.send();


}

In the console the result is:

Uncaught Gc {message: “not an Array or MVCArray”, name: “InvalidValueError”, stack: “Error↵ at new Gc (https://maps.googleapis.com/m… [_.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K, _.K]0: _.K1: _.K2: _.K3: _.K4: _.K5: _.K6: _.K7: _.K8: _.K9: _.K10: _.K11: _.K12: _.K13: _.K14: _.K15: _.K16: _.K17: _.K18: _.K19: _.K20: _.K21: _.K22: _.K23: _.K24: _.K25: _.K26: _.K27: _.K28: _.K29: _.K30: _.K31: _.K32: _.K33: _.K34: _.K35: _.K36: _.K37: _.K38: _.K39: _.K40: _.K41: _.K42: _.K43: _.K44: _.K45: _.K46: _.K47: _.K48: _.K49: _.K50: _.K51: _.K52: _.K53: _.K54: _.K55: _.K56: _.K57: _.K58: _.K59: _.K60: _.K61: _.K62: _.K63: _.K64: _.K65: _.K66: _.K67: _.K68: _.K69: _.K70: _.K71: _.K72: _.K73: _.K74: _.K75: _.K76: _.K77: _.K78: _.K79: _.K80: _.K81: _.K82: _.K83: _.K84: _.K85: _.K86: _.K87: _.K88: _.Klength: 89__proto__: Array[0]

If I include ‘ like this:

data2[i]= ‘new google.maps.LatLng(parseFloat(‘+ data[i].lat +’), parseFloat(‘+ data[i].lon +’))’;

works but throws the error: not an Array or MVCArray

please helpme!


Source: stackoverflow-javascript

Google maps opening infoWindow on first not clustered marker

I’am newbe. Sorry for my english. I made on my site(WordPress) page with google map. The markers cordinate are from every post who has acf(Advanced Custom Field) with lt, lng. When i click on the marker then open InfoWindow with thumbnaile and link to the post. I don’t know how force on the map that when map loads the first random non clustered marker Infowindow be visble

    
(function($) {

/*
*  render_map
*
*  This function will render a Google Map onto the selected jQuery element
*
*  @type    function
*  @date    8/11/2013
*  @since   4.3.0
*
*  @param   $el (jQuery element)
*  @return  n/a
*/

function render_map( $el ) {

// var
var $markers = $el.find('.marker');

// vars
var args = {
    zoom        : 10,
    center      : new google.maps.LatLng(0, 0),
    mapTypeId   : google.maps.MapTypeId.ROADMAP,
    scrollwheel : true
};

// create map               
var map = new google.maps.Map( $el[0], args);
$(window).resize(function() {
    // (the 'map' here is the result of the created 'var map = ...' above)
    google.maps.event.trigger(map, "resize");

  });
// add a markers reference
map.markers = [];




// add markers
$markers.each(function(){

    add_marker( $(this), map );

});

// center map
center_map( map );

markerCluster( map.markers, map );  


}
// create info window outside of each - then tell that singular infowindow to swap content based on click
var infowindow = new google.maps.InfoWindow({
content     : '' 
});

/*
*  add_marker
*
*  This function will add a marker to the selected Google Map
*
*  @type    function
*  @date    8/11/2013
*  @since   4.3.0
*
*  @param   $marker (jQuery element)
*  @param   map (Google Map object)
*  @return  n/a
*/

function add_marker( $marker, map ) {

// var
var latlng = new google.maps.LatLng( $marker.attr('data-lat'), $marker.attr('data-lng') );

// create marker
var marker = new google.maps.Marker({
    position    : latlng,
    map         : map
});

// add to array
map.markers.push( marker );

// if marker contains HTML, add it to an infoWindow
if( $marker.html() )
{




    // show info window when marker is clicked & close other markers
    google.maps.event.addListener(marker, 'click', function() {
        //swap content of that singular infowindow
                infowindow.setContent($marker.html());

                infowindow.open(map, marker);
    });


    // close info window when map is clicked
         google.maps.event.addListener(map, 'click', function(event) {
             if (infowindow) {
               infowindow.close(); }
            }); 


}

}

/*
*  center_map
*
*  This function will center the map, showing all markers attached to this map
*
*  @type    function
*  @date    8/11/2013
*  @since   4.3.0
*
*  @param   map (Google Map object)
*  @return  n/a
*/

function center_map( map ) {

// vars
var bounds = new google.maps.LatLngBounds();

// loop through all markers and create bounds
$.each( map.markers, function( i, marker ){

    var latlng = new google.maps.LatLng( marker.position.lat(), marker.position.lng() );

    bounds.extend( latlng );

});

// only 1 marker?
if( map.markers.length == 1 )
{
    // set center of map
    map.setCenter( bounds.getCenter() );
    map.setZoom( 16 );
}
else
{
    // fit to bounds
    map.fitBounds( bounds );
}

}

function markerCluster( markers, map ) {
    var markerCluster = new MarkerClusterer(map, markers, {imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});
    //console.log( markers );
    google.maps.event.addListener(map, 'idle', function() {

        console.clear();
             for ( i=0;i



  
'publish', 'post_type' => 'post', 'tax_query' => array( array( 'taxonomy' => 'post_format', 'terms' => array( 'post-format-gallery' ), 'field' => 'slug', ), ), 'posts_per_page' => -1, //sets to unlimited to pull all posts ) ); ?>
have_posts() ) : $mapposts->the_post(); ?> <?php endwhile; ?> </div><!-- .acf-map --> <?php wp_reset_query(); // Restore global post data stomped by the_post(). ?> Source: stackoverflow-javascript