0
当它能够确定用户的位置时,我得到了下面的JavaScript发布数据。
if (document.cookie.indexOf("latLng") == -1) {
console.log("fired geolocation lookup");
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error, {enableHighAccuracy:true,timeout:6000,maximumAge:2500});
} else {
//html5 geolocation isn't supported in this browser
error('not supported');
//render set location manually
}
} else if (document.cookie.indexOf("latLng") == 0) {
$(function() {
organiseLocation();
});
}
function success(position) {
//cool we've got the location
//var locationData = {"location": position.coords.latitude+", "+position.coords.longitude, "radius": 50, "type": "auto"};
console.log("position ", position);
$.ajax({
type: "POST",
url: "../set_location",
data: position,
dataType: "json",
success: function(){
console.log("success!");
}
});
}
function error(msg) {
//we couldn't determine your location
var s = document.querySelector('#status');
s.innerHTML = typeof msg == 'string' ? msg : "failed";
s.className = 'fail';
//this needs cleaning up!
console.log(arguments);
}
它工作正常,在Chrome中,不过在Firefox & Safari中我碰到下面的错误 - 任何想法?
Illegal operation on WrappedNative prototype object
[Break On This Error]
value = jQuery.isFunction(value) ? value() : value;
的参数来通过为{ “所在地”=> {}}位置对象肯定有东西,因为我已经注销了它。有任何想法吗? – Elliot 2012-04-01 19:08:36
我编辑了代码示例以序列化'locationData',这似乎是您感兴趣的数据。基本上,您应该能够将可序列化的任何内容串化并将其发送到服务器。 – slashingweapon 2012-04-01 22:01:45