git clone git@github.com:jbeuckm/cordova-plugin-geocoder.git
cd myproject
cordova plugin add ../cordova-plugin-geocoder
- iOS (via MapKit)
- Android (via Android Location)
- navigator.geocoder.geocodeString
To Forward geocode a given address to find coordinates.
navigator.geocoder.geocodeString(successCallback, errorCallback, addressString);
- addressString: The address to be geocoded. (String)
- nbMaxResults: The maximum number of addresses to be returned. (OPTIONAL, defaults to 1) (Int)
function onError(err) {
alert(JSON.stringify(err));
}
function onSuccess(coords) {
alert("The location is lat="+coords.latitude+", lon="+coords.longitude);
}
navigator.geocoder.geocodeString(onSuccess, onError, "55418");
To forward geocode a given address with multiple results.
navigator.geocoder.geocodeString(successCallback, errorCallback, addressString , nbMaxResults);
function onError(err) {
alert(JSON.stringify(err));
}
function onSuccess(coords) {
for (var i = 0; i<2; i++) {
alert("The location is lat=" + coords[i].latitude + ", lon=" + coords[i].longitude + ", address=" + coords[i].address);
}
}
navigator.geocoder.geocodeAllString(onSuccess, onError, "rue de paris", 2);