我正在使用此代码来获取用户的完整地址信息
function getGeo() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (a) {
$("#geoLoc").html("Determing your location..");
$.post("https://mysite.com/getloc.php?l=" + a.coords.latitude + "," + a.coords.longitude, function (b) {
var c = jsonParse(b);
geo_adres = c.results[0].formatted_address;
latitude = a.coords.latitude;
longitude = a.coords.longitude;
$("#geoLoc").html(c.results[0].formatted_address);
$("#geoLoc").show("slow")
})
}, function (a) {
alert(geolocationErrorMessages[a.code])
}, {
enableHighAccuracy: true,
maximumAge: 12e4
});
return false
} else {
alert("Your browser doesn't support geo-location feature...")
}
}编辑: getloc.php包含以下代码(javascript中的c var )
$data = file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?latlng=". $_GET['l'] ."&sensor=false");
print $data;实际上,我想要的就是像city, country那样给用户提供城市和国家的信息
我应该如何改变这个c.results[0].formatted_address来实现这个目标呢?
发布于 2012-09-06 13:58:47
试试这段有效的php代码,我希望这会对你有很大的帮助:),如果有任何疑问,请让我知道--
<?php
$data = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=false");
$jsonnew =json_decode($data,true);
echo "<pre>";
print_r($jsonnew['results'][7]['address_components'][2]['long_name']);
echo "<pre>";
print_r($jsonnew['results'][6]['address_components'][2]['long_name']);发布于 2012-09-06 15:22:41
你不应该需要你的getloc脚本。Maps Javascript API包括一个Geocoder类。
https://stackoverflow.com/questions/12293536
复制相似问题