PDA

View Full Version : I want to retrieve latitude and longitude from geolocation !



Shariar Shaikot
22 Dec 2011, 6:40 AM
Hello experts,
I want to know, how would I retrieve Latitude and Longitude from geolocation.
I want to send that via JSON param to my server for storing in my SQL database.
Is it possible to get it as string?

mitchellsimoens
22 Dec 2011, 7:43 AM
From the API docs:


var geo = new Ext.util.GeoLocation({
autoUpdate: false,
listeners: {
locationupdate: function (geo) {
alert('New latitude: ' + geo.latitude);
},
locationerror: function ( geo,
bTimeout,
bPermissionDenied,
bLocationUnavailable,
message) {
if(bTimeout){
alert('Timeout occurred.');
}
else{
alert('Error occurred.');
}
}
}
});
geo.updateLocation();

You can see in the locationupdate listener?

Shariar Shaikot
22 Dec 2011, 8:22 AM
Yes I can see.
But I tried to retrieve the geo.latitude and geo.longitude in a var to send it via jsonp request.
But both of the var was empty.
I tried:

var geo = new Ext.util.GeoLocation({
autoUpdate: true,
listeners: {
locationupdate: function (geo) {
var lat = geo.latitude;
var lng = geo.longitude;

}
}
});

geo.updateLocation();

mitchellsimoens
22 Dec 2011, 8:25 AM
You did the JsonP request in the locationupdate listener?

Shariar Shaikot
22 Dec 2011, 8:27 AM
No!
If I use that it would be work?

mitchellsimoens
22 Dec 2011, 8:32 AM
Getting location is async so you need to do it in the event listener

Shariar Shaikot
22 Dec 2011, 8:36 AM
Thanks a lot for your help.