Я пытаюсь преобразовать адрес в широту и долготу, но значения не отображаются. Я даже хочу сохранить результат в базе данных, но я не могу получить 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>
сообщения Какие ошибки вы видите в консоли JavaScript в браузере? Есть одна вопиющая ошибка - 'Documet' –
Ошибка. Его просто не отображается. @Pekka 웃 – Shraddha
В * ошибке * в * var address = Documet.getElementById ("адрес"); * из-за опечатки 'Documet'. Вы уверены, что ищете консоль ошибок? –