How do I return a longitude and latitude from Google Maps JavaScript geocoder? [duplicate]

because your function codeAddress is executed, assigning empty array to loc, executing asynchronous request to google geocoder and returns loc, which is empty, because its real value is assigned when response from google comes. In other words, allert should be inside response handler: var geocoder; var map; function initialize() { geocoder = new google.maps.Geocoder(); var … Read more

Get latitude and longitude based on location name with Google Autocomplete API

You can use the Google Geocoder service in the Google Maps API to convert from your location name to a latitude and longitude. So you need some code like: var geocoder = new google.maps.Geocoder(); var address = document.getElementById(“address”).value; geocoder.geocode( { ‘address’: address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { // do something with the … Read more

How to convert an address to a latitude/longitude?

Google has a geocoding API which seems to work pretty well for most of the locations that they have Google Maps data for. http://googlemapsapi.blogspot.com/2006/06/geocoding-at-last.html They provide online geocoding (via JavaScript): http://code.google.com/apis/maps/documentation/services.html#Geocoding Or backend geocoding (via an HTTP request): http://code.google.com/apis/maps/documentation/services.html#Geocoding_Direct The data is usually the same used by Google Maps itself. (note that there are some … Read more

How do i return coordinates after forward geocoding?

You are correct about the asynchronous issue. Basically, you cannot do anything after this code: // [A1] self.geocoder.geocodeAddressString(combinedAddress, completionHandler: { (placemarks, error) -> Void in // [B] … put everything _here_ }) // [A2] … nothing _here_ The reason is that the stuff inside the curly braces (B) happens later than the stuff outside it … Read more

iOS – MKMapView place annotation by using address instead of lat / long

Based on psoft‘s excellent information, I was able to achieve what I was looking for with this code. NSString *location = @”some address, state, and zip”; CLGeocoder *geocoder = [[CLGeocoder alloc] init]; [geocoder geocodeAddressString:location completionHandler:^(NSArray* placemarks, NSError* error){ if (placemarks && placemarks.count > 0) { CLPlacemark *topResult = [placemarks objectAtIndex:0]; MKPlacemark *placemark = [[MKPlacemark alloc] … Read more

ggplot centered names on a map

Since you are creating two layers (one for the polygons and the second for the labels), you need to specify the data source and mapping correctly for each layer: ggplot(ny, aes(long, lat)) + geom_polygon(aes(group=group), colour=”black”, fill=NA) + geom_text(data=cnames, aes(long, lat, label = subregion), size=2) Note: Since long and lat occur in both data frames, you … Read more