Skip to content

Map.getMyLocation()

wf9a5m75 edited this page Sep 23, 2014 · 11 revisions

The callback function will be involved with current your location as Location data.

###Description #####Android As of version 1.2.0, the plugin uses Fused location provider for Android 3.0 and higher. This might help to save the battery. Android 2.3 uses Location Client.

However requestLocationUpdates does not return for some cases. If you are not satisfied, use HTML5 geolocation API.

#####iOS Always use the Core Location.

###enableHighAccuracy option As of v1.2.0, you can specify enableHighAccuracy option that attempt to get your location with highest accuracy.

var opts = {
  enableHighAccuracy: true
};
map.getMyLocation(opts, onSuccess, onError);

###Code

var onSuccess = function(location) {
  var msg = ["Current your location:\n",
    "latitude:" + location.latLng.lat,
    "longitude:" + location.latLng.lng,
    "speed:" + location.speed,
    "time:" + location.time,
    "bearing:" + location.bearing].join("\n");
  
  map.addMarker({
    'position': location.latLng,
    'title': msg
  }, function(marker) {
    marker.showInfoWindow();
  });
};

var onError = function(msg) {
  alert("error: " + msg);
};
map.getMyLocation(onSuccess, onError);

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