サイトに Google マップ モジュールが必要です。地図は、郵便番号に従って表示する必要があります。郵便番号は、住所/緯度と経度に自動的に変換されます。
1 に答える
0
まあ私はPHPでそれをしました..コードを見つけてください..AJAX呼び出しを行うと、緯度と経度が返されます..のように
$address = $this->input->post('address');
$output = array();
$address = str_replace(" ", "+", $address);
$region = "IND";
$json = file_get_contents("http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false®ion=$region");
$json = json_decode($json);
if (!empty($json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'})) {
$output['latitude'] = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
$output['longitude'] = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
return $output;
}
次に、返された緯度と経度をGoogleマップAPIで場所に設定します
//var latlng = new google.maps.LatLng(-104.017031, 15.373535);
var latlng = new google.maps.LatLng(latitude,longitude);
var map = new google.maps.Map(document.getElementById('map'), {
center: latlng,
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: 'Set lat/lon values for this property',
raiseOnDrag: true,
draggable: true
});
google.maps.event.addListener(marker, 'dragend', function(a) {
console.log(a);
$('#latitude').val(a.latLng.lat().toFixed(4));
$('#longitude').val(a.latLng.lng().toFixed(4));
// var div = document.createElement('div');
// div.innerHTML = a.latLng.lat().toFixed(4) + ', ' + a.latLng.lng().toFixed(4);
// document.getElementsByTagName('body')[0].appendChild(div);
});
ページに google map.js ファイルを含めてください
お役に立てれば
于 2012-04-12T05:04:56.353 に答える