我已经查看了文档和整个网络,但无法找到此用例的示例。
给定一个邮政编码,我需要以纬度/经度坐标的形式粗略地估计用户的位置。我只有邮政编码,没有其他信息。
是否可以使用Google Maps API完成此操作?如果不能,您建议查看哪些其他资源?
我已经查看了文档和整个网络,但无法找到此用例的示例。
给定一个邮政编码,我需要以纬度/经度坐标的形式粗略地估计用户的位置。我只有邮政编码,没有其他信息。
是否可以使用Google Maps API完成此操作?如果不能,您建议查看哪些其他资源?
function getLnt($zip){
$url = "http://maps.googleapis.com/maps/api/geocode/json?address=".urlencode($zip)."&sensor=false";
$result_string = file_get_contents($url);
$result = json_decode($result_string, true);
$result1[]=$result['results'][0];
$result2[]=$result1[0]['geometry'];
$result3[]=$result2[0]['location'];
return $result3[0];
}
$coords = str_replace(' ','',$foo->zipcode);*
$val = getLnt($coords);
/* print latitude & longitude for example */
print $val['lat'];
print $val['lng'];
function initialize(){
var myLatlng = new google.maps.LatLng(<?= $val['lat'] ?>,<?= $val['lng'] ?>);
var mapOptions = {
zoom: 14,
center: myLatlng,
disableDefaultUI: true,
scrollwheel: false,
}
var map = new google.maps.Map(document.getElementById('propMap'), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'title of location',
icon: iconBase + 'google-marker.png'
});
}