私はGoogleマップを初めて使用し、html5を使用してユーザーの緯度と経度の座標を取得しましたが、ユーザーがそれを選択できるように、ユーザーの最も近い場所の名前を取得したかったのです(クリックできるのに入力するのはなぜですか?)何もできません。私は今日これらのスクリプトを書きました....
<!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to get your position:</p>
<button onclick="getLocation()">Try It</button>
<div id="mapholder"></div>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=true">
//only a v3 api library
</script>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script>
var x=document.getElementById("demo");
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition,showError);
}
else{x.innerHTML="Geolocation is not supported by this browser.";}
}
function showPosition(position)
{
lat=position.coords.latitude;
lon=position.coords.longitude;
latlon=new google.maps.LatLng(lat, lon)
mapholder=document.getElementById('mapholder')
mapholder.style.height='250px';
mapholder.style.width='500px';
var myOptions={
center:latlon,zoom:18,
mapTypeId:google.maps.MapTypeId.ROADMAP,
mapTypeControl:false,
navigationControlOptions:{style:google.maps.NavigationControlStyle.SMALL}
};
var map=new google.maps.Map(document.getElementById("mapholder"),myOptions);
var marker=new google.maps.Marker({position:latlon,map:map,title:"Some where here"});
var geocoder = new google.maps.Geocoder();
geocoder.geocode({latLng:latlon},function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
infoWindow.setContent(results[0].formatted_address);
infoWindow.setPosition(event.latLng);
infoWindow.open(map);
}
}
});
}
function showError(error)
{
switch(error.code)
{
case error.PERMISSION_DENIED:
x.innerHTML="User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML="Location information is unavailable."
break;
case error.TIMEOUT:
x.innerHTML="The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
x.innerHTML="An unknown error occurred."
break;
}
}
</script>
</body>
</html>
私はこれまでにこれらすべてを行ってきましたが、今私がする必要があるのは、これらの 2 つの変数によって指定された場所の場所名を取得したいということです:lat,lon
場所名を見つけることができるように、誰か助けてくれませんか? 役立つかもしれないこのリンクを見つけましたが、理解できません。地図に場所情報は必要ありませんが、変数に場所名を取得したい
よろしくお願いします..質問が明確でない場合は、私に言及してください。より明確にするために、、、、私の言葉で申し訳ありません....