Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Based on your comment to @Rushyo's answer- it seems like you know enough about Javascript and the Google Maps API to construct those functions. I'm a little confused as to what you're looking for.</p> <p>I would suggest however, that you add lat/lon coordinates to your database in the first place. You shouldn't have to geocode the addresses every time the map is loaded.</p> <p><strong>Update:</strong> In response to your comment below, here is the code you referenced - along with the <code>addAddressToMap()</code> function called by the Geocoder. It creates a marker for each address and adds it to the array <code>markerList</code>. You can then access the markers in that array later, since we initialized it outside the scope of the <code>addAddressToMap()</code> function.</p> <pre><code>for(var i = 0; i &lt; locations.length; i++) { var address = locations[i]['address'] + ', ' + locations[i]['city'] + ' ' + locations[i]['state'] + ', ' + locations[i]['zip_code']; geocoder.getLocations(address, addAddressToMap); } var markerList = new array(); function addAddressToMap(response) { if (!response || response.Status.code != 200) { alert("\"" + address + "\" not found"); } else { place = response.Placemark[0]; point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]); marker = new GMarker(point); markerList.push(marker); map.addOverlay(marker); } } </code></pre> <p><strong>Update 2:</strong> In response to the code you posted in your question above, you're probably getting random numbers in <code>currentLocation</code> because of the asynchronous nature of the Geocoder. Remember that your <code>getLocations()</code> function will send requests for every location in the array before it gets any responses back.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload