Skip to content

Geocoder

wf9a5m75 edited this page Sep 28, 2014 · 10 revisions

#Note that there is a bug in version 1.2.1, the Geocoder.geocode does not work. The bug will be fixed in version 1.2.2.

###Geocoding This plugin supports geocoding. You can convert address or landscape names to latitude and longitude. In Android, this plugin uses Google Play Services feature, while in iOS this plugin uses iOS feature (not Google).

var request = {
  'address': $("#geocoder_input").val()
};
plugin.google.maps.Geocoder.geocode(request, function(results) {
  if (results.length) {
    var result = results[0];
    var position = result.position; 
    
    map.addMarker({
      'position': position,
      'title':  JSON.stringify(result.position)
    }, function(marker) {
      
      map.animateCamera({
        'target': position,
        'zoom': 17
      }, function() {
        marker.showInfoWindow();
      });
      
    });
  } else {
    alert("Not found");
  }
});

###Reverse geocoding This plugin also supports reverse geocoding.

var request = {
  'position': GOOGLE
};
plugin.google.maps.Geocoder.geocode(request, function(results) {
  if (results.length) {
    var result = results[0];
    var position = result.position; 
    var address = [
      result.subThoroughfare || "",
      result.thoroughfare || "",
      result.locality || "",
      result.adminArea || "",
      result.postalCode || "",
      result.country || ""].join(", ");
    
    map.addMarker({
      'position': position,
      'title':  address
    });
  } else {
    alert("Not found");
  }
});

Join the official community

New versions will be announced through the official community. Stay tune!

Do you have a question or feature request?

Feel free to ask me on the issues tracker.

Or on the official community is also welcome!


New version 2.0-beta2 is available.

The cordova-googlemaps-plugin v2.0 has more faster, more features.

https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/tree/master/v2.0.0/README.md

Clone this wiki locally