Please can any one 开发者_Python百科help me get the latitude/longitude location of the user. I have tried many things but I'm not able to solve this problem. If anyone has an idea please help me.
I'm a beginner in iPhone so please give brief explanation.
I assume you mean in the browser (not a native application), since you have tagged this question as javascript. You do it via an asynchronous callback:
//Function that does something once the device has a location
//May be called repeatedly
function handler(location) {
var longitude = location.coords.longitude;
var latitude = location.coords.latitude;
var accuracy = location.coords.accuracy
//Do something with them
}
//Register the handler and tell the phone to start finding a location
navigator.geolocation.getCurrentPosition(handler);
It is all part of the HTML5 geolocation stuff, there is a draft here.
精彩评论