私はhtmlの市町村名はどのようにして取得できますか?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Geolocation</title>
<script src="https://code.jquery.com/jquery-2.2.3.min.js" integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo=" crossorigin="anonymous"></script>
<script src="funciones.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
</head>
<body>
<button id="startGeo">Click here to check your geolocation abilities</button>
</body>
</html>
でこれをhhaveと私はfunction.jsファイルでこれを持っている:
$(document).ready(function(){
$("#startGeo").click(checkLocation);
function checkLocation(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(getLocation,locationFailed);
//document.write("you have geolocation");
}
else {
document.write("you don't have geolocation");
}
}//ends checkLocation()
function getLocation(position){
var latitud = position.coords.latitude;
var longitud = position.coords.longitude;
var exactitud = position.coords.accuracy;
alert("latitud: " + latitud + " longitud: " + longitud + " exactitud: " + exactitud);
//document.write("we received your location");
}
function locationFailed(){
document.write("we didn't get your location. Please check your settings");
}
});
このことから私は、座標を取得するが、私はどのように上まったく見当がつかない都市名...または州名を取得します。私はこれに似た質問をしましたが、彼らはjsonを使っているようでした。私はマップを望んでいない、ちょうど情報、それはテキストまたはアラートにすることができます。何かお考えですか?
あなたはAPIサンプルコール逆ジオコーディングを使用することができます
ありがとうございます。確かに私は情報を得るあなたの助けに感謝しますが、間違っている、それは私に私が知らないアドレスを与える。それはおそらくapiのjsonの問題ですか?私は他のコードを実行し、それは私が使用するブラウザによって異なる場所を与えます。 これはdata.results [2]と関係があるのだろうかと思います。そのような場合は、どのようなものを使用するのかをどのように知ることができますか? –
確かにそれはデータの結果に依存します。[2]ここでは例として2を書いています –
レスポンスについてもっと知るためにAPIドキュメントをチェックしてください: –