【发布时间】:2016-05-14 19:57:59
【问题描述】:
我正在尝试将地址转换为纬度和经度,但值未显示。 我什至想将结果存储在数据库中,但我无法首先获得纬度/经度。我想知道我哪里出错了。
下面是代码:
<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 웃
-
由于
Documet的拼写错误,var address = Documet.getElementById("address");有一个错误得到。您确定要查看错误控制台吗? -
@Shraddha:你得到这个问题的答案了吗?
-
不,我希望它获取我们输入的地址并将其转换为纬度和经度@Nana Partykar
标签: html geolocation geocoding