sgruhier / jquery-addresspicker

JQuery UI widget : address autocomplete field by google maps V3 geocoding service
xilinus.com/jquery-addresspicker/demos/index.html
593 stars 222 forks source link

Reverse Geocoding to show current address before moving marker #53

Open mrcharis opened 10 years ago

mrcharis commented 10 years ago

HI there Great plugin , is amazing.

Is there anyway to show the current geo location, in the address field?

Currently the address box remains empty until you move the marker, which is great, but I would like to show the current geolocation in the address box, before moving the marker.

I have my map currently centered on vietnam, but I would like to have the main location marker exactly on my current location address with the address displayed in the address box.

Cheers

Any help would be great

sgruhier commented 10 years ago

Thanks for appreciating this widget. If I have time, I'll do a full rewrite with new Google API!

For your issue, it looks hackish but just add this

google.maps.event.trigger($("#addresspicker_map").addresspicker("marker"), "dragend");

After you addresspicker initialisation, it should make it.

mrcharis commented 10 years ago

Hi there Thanks for your reply I used the code you supplied and now the address box has the initial current location (that I set as the center point) Works really great

I am still trying to load the geolocation, my current location as the center of the map, but having trouble getting it to work

I can retrieve the current location, but I cannot get the location to load into the address picker before the map appears , and so I have no map showing

This is the code I am using

window.onload=function(){
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
else
{
alert("Geolocation is not supported by this browser.");
}
}
function showPosition(pos){
alert("Latitude: "+pos.coords.latitude+"\nLongitude: "+pos.coords.longitude);

  var lat = startPos.coords.latitude;
  var long = startPos.coords.longitude;

}

\\ then I use the variables to set the center point
 center: new google.maps.LatLng(lat , long ),

problem is it doesn' work

Do you have any idea how to get it working?

Any help would be great, and would be a good addition to your plugin for future users

Thanks again

Have a nice day