使用getElementById时不显示lat和lng
lat and lng not displayed when using getElementById
我通过地址获取纬度和经度。一切都很好,我可以毫无问题地显示地图,但我想显示海拔和经度。
这是我的代码,我正在体内初始化
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>
好吧,发现代码工作得很好
function updateCoordinates(latlng)
{
if(latlng)
{
document.getElementById('lat').value = latlng.lat();
document.getElementById('lng').value = latlng.lng();
}
}
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);
updateCoordinates(results[0].geometry.location);
if (marker) marker.setMap(null);
marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
draggable: true
});
google.maps.event.addListener(marker, "dragend", function() {
updateCoordinates(marker.getPosition());
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
相关文章:
- 使用getElementById时不显示lat和lng
- 从GeoJson文件中获取单独的Lat和Lng值
- 通过lat和lng值设置标记
- 本地存储上的传单标记,如何获取标记 lat lng 并从存储中排除
- 谷歌地图API - 在数组中使用Lat Lng坐标绘制折线飞行路径
- 循环对象数组,直到lat/lng不为零
- 从多边形(多边形)边界内的多边形中心生成n个随机点(Lat-Lng对)
- googlemaps移动标记与来自ajax的lat/lng成功返回数据
- 将lat/lng坐标转换为给定地图上的像素(使用JavaScript)
- 使用getCenter()创建GMap Lat/Lng对象时,v3.22中出现错误
- 如果我有一个lat/lng我假设它在(0,0)那么我如何计算另一个lat/lng对的x, y坐标
- 推Lat/Lng到多边形数组的麻烦-谷歌地图
- Google Maps V3 API——当动态创建标记时,我想获得基于lat/lng的县
- 如何在Angularjs中使用ngMap访问地图标记的当前位置(lat, lng) ?
- 如何将react-google-maps中的lat/lng添加到此.state.markers
- 标记GoogleMaps Lat/Lng交叉口
- 如何从谷歌地图API函数中获得javascript lat/lng变量
- Google Geocoder为几个不同的地址返回同一组lat/lng.Lat/Lng是城市或乡镇的坐标,而不是地址
- 地理编码输出是相同lat/lng的3倍
- 将lat/lng坐标转换为给定旋转地图上的像素