Logicify / jquery-locationpicker-plugin

JQuery Location Picker plugin
MIT License
389 stars 260 forks source link

Get my current location #13

Closed supun151515 closed 9 years ago

supun151515 commented 10 years ago

Is there a way to get my current location? If yes, kindly explain it. Put it in your documentation as well.

Thank you, Supun Silva

corvis commented 10 years ago

Hi,

Yes there is, but it is not supported by the plug-in out of the box. You just need to do something like:

// Initialize component
$('#somecomponent').locationpicker();
// Get current location from the browser
navigator.geolocation.getCurrentPosition(function(position) {
  // You can set it the plugin
  $('#somecomponent').locationpicker('location', {
    latitude: position.coords.latitude,
    longitude: position.coords.longitude,
  });
});

But you should keep in mind that:

if ("geolocation" in navigator) {
  /* geolocation is available */
} else {
  /* geolocation IS NOT available */
}

Let me know if this works for you.

Cheers, Dmitry