我想將地址轉換爲經度和緯度,但值不顯示。 我甚至想將結果存儲在數據庫中,但我無法在第一時間獲得經緯度。我想知道我出錯的地方。將地址轉換爲經度和緯度
下面是代碼:
<html>
<head>
<title>Theater</title>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&language=en" ></script>
<script>
// Called when page is loaded
function Init()
{
var address = Document.getElementById("address");
var city = Document.getElementById("city");
var state = Document.getElementById("state");
var zip = Document.getElementById("zip");
var country = Document.getElementById("country");
// make google call to convert address to lat/lng coordinate
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address+city+state+zip+country}, ShowLatLng);
}
// This function is the called when Google geocode() returns the result of geocoding an address
function ShowLatLng(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
document.getElementById('latlng').innerHTML = results[0].geometry.location;
}
}
</script>
</head>
<body>
<table><tr>
<td> Address   </td>
<td><input type="text" name="address" id="address"> </td> </tr>
<tr><td> City</td><td><input type="text" name="city" id="city"></td>
<td>State </td><td><input type="text" name="state" id="state"></td></tr>
<tr><td>zip</td><td><input type="text" name="zip" id="zip"></td>
<td>Country</td><td><input type="text" name="country" id="country"></td>
</tr></table>
<input type="button" onclick="Init()" value="Determine Lat/Lon">
<label id="latlng"></label>
什麼錯誤信息,你在瀏覽器的JavaScript控制檯看到?有一個明顯的錯誤 - 「Documet」 –
沒有錯誤。它只是不顯示。 @Pekka웃 – Shraddha
在* var address = Documet.getElementById(「address」); *由於錯誤'Documet',* got *是錯誤的。你確定你正在尋找錯誤控制檯嗎? –