Thanks Larry, in case anyone gets this issue, this is what I did to fix it:
//takes a google.LatLng object //returns an array with city at [0] amd country at [1] function reverseGeocode(marker) { var location = new Object(); city = ["administrative_area_level_1", "political"]; country = ["country", "political"]; var geocoder = new google.maps.Geocoder(); geocoder.geocode({location: marker.getPosition()}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { for(i=0; i < results[0].address_components.length; i++) { if((location.city && location.country) == null) { if(results[0].address_components[i].types[0] == city[0] && location.city == null) { location.city = results[0].address_components[i].long_name; } else if(results[0].address_components[i].types[0] == country[0] && location.country == null) { location.country = results[0].address_components[i].long_name; } } } marker.city = location.city; marker.country = location.country; } }); } On Nov 5, 12:36 am, "geocode...@gmail.com" <geocode...@gmail.com> wrote: > On Nov 5, 12:34 am, Rob <rob.feli...@gmail.com> wrote: > > > Thanks for helping out, so I followed your suggestion of doing a > > reverse geocode when dropping the marker, such as: > > > markerLocation = > > reverseGeocode(marker.getPosition()); > > alert(markerLocation.city); > > > However, markerLocation is always null, even though within the > > reverseGeocode function, the city is being populated properly. I am > > assuming this is because JS doesn't wait for the AJAX request to be > > completed, and just continues executing the rest of the code. Any > > idea on how to solve this? > > the reverse geocoder is asynchronous, you can't return a value from it > like that. > > set the position of the marker in the callback routine. > > -- Larry > > > > > > > > > > > On Nov 4, 6:46 pm, Rossko <ros...@culzean.clara.co.uk> wrote: > > > > > I have a map where I drop a number of markers. > > > > That would be the time to do reverse gecoding? > > > > > I need to save the > > > > location of the markers to a database, along with the city and country > > > > that the marker was placed in. > > > > Beware the terms of use for storing Google's data > > > > > Any way I can do this synchronously? > > > > No, but you can write code that simulates it e.g. execute one request, > > > when response comes execute the next, when all complete do whatever > > > else. The next pitfall will be the limited rate of request allowed, > > > to prevent abuse. -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group, send email to google-maps-js-api-v3@googlegroups.com. To unsubscribe from this group, send email to google-maps-js-api-v3+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.