我正在按地址获取纬度和经度。一切正常,我可以毫无问题地显示地图,但我想显示高度和经度。
这是我的代码,我在正文中初始化
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);
}
google.maps.event.addListener(marker, 'click', function() {
document.getElementById('lat').value = results[0].geometry.location.lat();
document.getElementById('lng').value = results[0].geometry.location.lng();
});
});
}
这是用法:
<div id="mapholder"></div>
</p>
<div id="map_canvas"></div>
<div id="info"></div>
<div>
<input id="address" type="textbox" value="הזן כתובת">
<input type="button" value="מצא את מיקומך" onclick="codeAddress()"><br>
<input type="button" value="מצא קופונים באזורך" onclick="showPositionCoupons(32.105892, 35.198483)"><br>
Latitude: <input type="text" id="lat"><br>
Longitude: <input type="text" id="lng"><br>
</div>