我试图创建一个Gmap来允许人们对地址进行地址解析并找到相应的经纬度。我想用我已经创建的表单来看这个。另外,我希望能够在拖动标记时更改坐标。如何从地理编码地址找到经纬度?
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="UTF-8">
<title>Geocoder 10</title>
<style>
#map_canvas { width:400px; height:450px; }
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-30.070, -51.190);
var myOptions = {
zoom: 9,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
draggable: true,
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas"></div>
<div>
<input id="address" type="textbox" value="">
<input type="button" value="Localizar!" onclick="codeAddress()"><br>
Latitude: <input type="text" id="lat"><br>
Longitude: <input type="text" id="lng"><br>
</div>
</body>
</html>
'结果[0] .geometry.location'里面是不是'lat/lng'? :) – 2012-08-14 01:50:11
你能解释一下吗?我对这个Gmaps Gecoding的'东西'很新颖......如果价值已经存在,我该如何在表单中展示它?非常感谢! – 2012-08-14 01:58:00
让我举一个例子。 http://gmaps-samples.googlecode.com/svn/trunk/geocoder/singlegeocode.html/ – Jessedc 2012-08-14 02:02:31