Note that there are some explanatory texts on larger screens.

plurals
  1. POUndefined on Google Map Api v3 Reverse Geocoding
    text
    copied!<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/11798431/undefined-is-not-a-function-google-geolocation">Undefined is not a function, Google Geolocation</a> </p> </blockquote> <p>I am trying to get google reverse geocoding of location, it returns me undefined but on console.log it shows address</p> <p>this is the function to get the value</p> <pre><code>function getLatLng(latlng, callback) { var codedAddress; geocoder.geocode({'latLng': new google.maps.LatLng(40.730885,-73.997383)}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { codedAddress = results[1].formatted_address; console.log("codedAddress 1 = "+codedAddress); } else { alert("There was a problem with the map"); } console.log("codedAddress 2 = "+codedAddress); }); callback(codedAddress); } </code></pre> <p>and this is my init code</p> <pre><code>function initialize() { var mapOptions = { zoom: 11, center: new google.maps.LatLng(5.386, 100.245), mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions); var location_coords = [ &lt;?php echo $output; ?&gt; ]; var location_status = [ &lt;?php echo $status; ?&gt; ]; var location_users = [ &lt;?php echo $users; ?&gt; ]; var location_date = [ &lt;?php echo $date; ?&gt; ]; for(i=0;i&lt;location_coords.length;i++) { var traffic_options = { strokeColor: '#A52A2A', strokeOpacity: 0.8, strokeWeight: 1, fillColor: getColor(location_status[i]), fillOpacity: 0.5, map: map, center: location_coords[i], radius: 300 }; cityCircle = new google.maps.Circle(traffic_options); barr[i] = new Object; var marker = new google.maps.Marker({ position: location_coords[i], map: map, }); barr[i].marker = marker; barr[i].html = "&lt;div&gt;&lt;span style='font-size:9px'&gt;Reported by " + location_users[i] + " on " + location_date[i] + "&lt;/span&gt;" + "Traffic Location: " + getLatLng(location_coords[i], function(codedAddress) { return codedAddress; }) + "&lt;p&gt;Traffic Condition: " + getCondition(location_status[i]) + "&lt;/p&gt;&lt;/div&gt;"; barr[i].infoWindow = new google.maps.InfoWindow({ content: barr[i].html }); barr[i].listener = makeClosure(i, barr[i].marker); } } </code></pre> <p>The problem is within this statement</p> <pre><code>"Traffic Location: " + getLatLng(location_coords[i], function(codedAddress) { return codedAddress; }) </code></pre> <p>How do i get the value over here instead of "undefined"</p> <p>Thank you</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