7
點擊地圖後我需要獲取地址和座標,我使用谷歌地圖API v3,我恢復了輸入的座標,但我也需要點的地址。點擊地圖後獲取地址
function initialize() {
var myOptions = {
center: new google.maps.LatLng(36.835769, 10.247693),
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
google.maps.event.addListener(map, 'click', function(event) {
placeMarker(event.latLng);
});
var marker;
function placeMarker(location) {
if(marker){ //on vérifie si le marqueur existe
marker.setPosition(location); //on change sa position
}else{
marker = new google.maps.Marker({ //on créé le marqueur
position: location,
map: map
});
}
latitude.value=location.lat();
longitude.value=location.lng();
}
}
我用這個php腳本得到的地址,但如果不知道如何使用它在JavaScript? 我可以使用JavaScript獲取地址嗎?
<?php
$url = 'http://where.yahooapis.com/geocode?location=40.714224,-73.961452&gflags=R&flags=J';
$response = json_decode(file_get_contents($url));
$location = $response->ResultSet->Results[0];
foreach ((array) $location as $key => $value) {
if($key == 'city')
$city = $value;
if($key == 'country')
$country = $value;
if($key == 'street')
$street = $value;
}
echo "Street: ".$street."<br>";
echo "City: ".$city;
echo "<br/>Country: ".$country;
?>
感謝了很多人,它的工作;) – Houx
不客氣! –
拜託,我用法語得到結果,我需要英語,任何想法。 – Houx