我有這樣的代碼,如何獲取通過輸入框輸入的城市/國家的經度和緯度?
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function myIP(){
$("#btn").click(function(){
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': '#city'}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
alert("location : " + results[0].geometry.location.lat() + " " +results[0].geometry.location.lng());
} else {
alert("Something got wrong " + status);
}
});
});
}
</script>
</head>
<body onload="myIP()">
<input type="text" id= "city">
<input id="btn" type="button" value="get Lat&Long" />
</body>
</html>
這會給我的緯度和小對話框中輸入城市的經度。但我需要在同一頁面或父頁面。請幫我
這是你自己的代碼?在這種情況下,你有什麼嘗試? –
不是我的代碼。我試圖通過php輸入表單徒勞地輸入它。 – phpbeg
當我嘗試使用這個時,無論我輸入什麼,我都得到相同的座標。 –