How can I associate a Google Maps Geocoder callback response with my custom data?
I have this code using the Google Maps JavaScript API to geocode a series of addresses:
geocoder.geocode( { 'address': address }, function( results, status ) {
if ( status == google.maps.GeocoderStatus.OK )
{
// Place marker on map
}
Those addresses are "linked" to some custom data of me, and I would like to know "what" that address is linked to. I just want to know which one of my objects this geocoding callback corresponds to.
A more appropiate question would be: can I send a "custom" or "data" parameter to geocoder开发者_如何转开发.geocode() resultsand have it returned back to me through the callback function (maybe in the "results" object in the callback)?
Thanks!
Are you making multiple calls asynchronously or is this, as it appears, a single call based on an address?
In your code, you have the context already (the adress you are "finding"), but you are not keeping it with the "place marker on map" routine. Unless you have set this up asynchronously, the code flow should make it easy to match your data to the geocoding and marker.
Am I missing something?
Oh, forget about this.. I was just doing something stupid here.. This is my whole function for adding a marker geocoding the address first:
function addEventToMap( address, label )
{
geocoder.geocode( { 'address': address }, function( results, status ) {
if ( status == google.maps.GeocoderStatus.OK )
{
// Add marker with "label" on it
}
});
}
I wasn't getting the "label" param and it turns out I was passing to it an empty value.. my bad!
精彩评论