我正在尝试将地址转换为纬度和经度,但值未显示。 我甚至想将结果存储在数据库中,但我无法在第一时间获得lat / long。我想知道我哪里出错了。
以下是代码:
<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>