【发布时间】:2013-04-24 06:27:12
【问题描述】:
我在 phonegap 中使用 HTML5 Geolocation API 来精确检测我的位置。我在印度工作,理想情况下,我应该能够看到我的位置,即印度浦那,但事实并非如此。
它将“美国加利福尼亚州旧金山”检测为我的位置。可能是什么问题?
谢谢大家。非常感谢您的帮助。
让我分享代码:)
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is loaded and it is now safe to make calls Cordova methods
//
function onDeviceReady() {
// onSuccess Callback
// This method accepts a `Position` object, which contains
// the current GPS coordinates
//
var onSuccess = function(position) {
var lattitude = position.coords.latitude;
var longitude = position.coords.longitude;
//Ajax Call
$.ajax({
url: 'http://maps.googleapis.com/maps/api/geocode/json?latlng='+lattitude+','+longitude+'&sensor=true',
success: function(data){
alert(data.results[0].formatted_address);
//alert(data.results[1].formatted_address);
},
error: function(data){
alert('error');
}
});//Ajax call ends
};
function onError(error) {
alert('code: '+ error.code + '\n' + 'message: ' + error.message + '\n');
}
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
【问题讨论】:
-
你是从模拟器得到这个吗?如果是这样,那是您的问题 - 模拟器的静态位置设置为 SF。
-
另外,仅供参考,地理位置不是 HTML5 的一部分。
标签: html cordova geolocation