var x = document.getElementById("demo");
function geoapp() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
}
else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
var lat = position.coords.latitude;
var longi = position.coords.longitude;
var appid = * * * * ;
var geoapp = 'http://where.yahooapis.com/geocode? l location=' + lat + ',' + longi + '&flags=J&gflags=R&appid=' + appid;
document.getElementById("demo").innerHTML = geoapp;
var my_JSON_object = {};
var http_request = new XMLHttpRequest();
http_request.open("GET", geoapp, true);
http_request.onreadystatechange = function() {
var done = 4,
ok = 200;
if (http_request.readyState == done && http_request.status == ok) {
my_JSON_object = JSON.parse(http_request.responseText);
document.getElementById("demo").innerHTML = my_JSON_object;
}
};
http_request.send(null);
}
这段代码从html5 geoapi获取坐标然后将它们发送到yahoo placefinder api但是
我在查询工作正常时无法接收json对象。 任何帮助将不胜感激