获得在谷歌地图点击标记的完整地址
Get full address of clicked marker in google maps
你能帮我用一下谷歌地图吗
我需要得到点击标记的完整地址,并在ASP标签控件中显示地址详细信息。事实上,我每次只显示一个标记。
E。展位号或门牌号:15街道名称:圣约瑟夫街郊区:西弗敦城市:约翰内斯堡纬度:24.8545经度:-28.23565
我使用以下JavaScript代码的地图和它的工作良好。
<script type="text/javascript">
var map;
var marker;
var address;
function initialize() {
var latitude = document.getElementById('<%= hdnLat.ClientID%>').value;
var longitude = document.getElementById('<%= hdnLng.ClientID%>').value;
var myLatlng = new google.maps.LatLng(longitude, latitude);
var mapOptions = {
zoom: 18,
center: myLatlng
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
marker = new google.maps.Marker({
position: myLatlng,
map: map,
draggable:true,
animation: google.maps.Animation.DROP
});
google.maps.event.addListener(marker, 'click', toggleBounce);
}
function toggleBounce() {
if (marker.getAnimation() != null) {
marker.setAnimation(null);
} else {
marker.setAnimation(google.maps.Animation.BOUNCE);
}
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
我使用以下ASP控件来处理地图。
<asp:HiddenField ID="hdnLng" runat="server" />
<asp:HiddenField ID="hdnLat" runat="server" />
<div id="map-canvas" style="height:425px;"></div>
<asp:Label ID="addressStandNo" runat="server"></asp:Label>
<asp:Label ID="addressStreetName" runat="server"></asp:Label>
<asp:Label ID="addressSuburb" runat="server"></asp:Label>
<asp:Label ID="addressCity" runat="server"></asp:Label>
<asp:Label ID="addressLatitude" runat="server"></asp:Label>
<asp:Label ID="addressLongitude" runat="server"></asp:Label>
<asp:Label ID="addressPostalCode" runat="server"></asp:Label>
我只需要获得地图上单击标记的详细信息(地址),并将这些值分配给上面列出的ASP控件。
提前感谢。
您必须在单击标记事件
时执行以下操作- 使用latlng反向地理编码获取位置信息
- 在asp标签中显示返回的地理编码响应信息。参考地理编码响应
//Add listener
google.maps.event.addListener(marker, "click", function(event) {
toggleBounce()
showInfo(this.position);
});
function showInfo(latlng) {
geocoder.geocode({
'latLng': latlng
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
// here assign the data to asp lables
document.getElementById('<%=addressStandNo.ClientID %>').value = results[1].formatted_address;
} else {
alert('No results found');
}
} else {
alert('Geocoder failed due to: ' + status);
}
});
}
相关文章:
- 在Delphi TWebBrowser中按地址显示谷歌地图
- 谷歌地图API v3:如何以2个动态地址为中心
- 如何将可拖动的谷歌地图标记的地址传递到输入字段中
- 点击谷歌地图API并获取地址
- 如何在标记谷歌地图中添加地址
- 谷歌地图API格式地址
- 如何使用谷歌地图api加载带有当前地址的地图
- 用城市名称(地址?)设置谷歌地图标记位置
- 如何在谷歌地图上显示我的数据库地址,不带lat和long
- 谷歌地图自动完成删除空格并在地址字符串中插入加号(+)
- 你如何制作一个以具有特定标签的地址为中心的谷歌地图
- 谷歌地图自动完成完整地址
- jQuery 自动完成与谷歌地图地址查找
- 地址到谷歌地图上的数据库
- 谷歌地图 api v3 对多个地址进行地理编码
- 如何在谷歌地图中从纬度和经度获取地址位置
- 通过地址或密码制作多个标记谷歌地图
- 搜索的地址与谷歌地图 api v3 上最近的现有地标之间的距离
- 如何在信息窗口中显示我的地理编码地址?谷歌地图API
- 获取格式整齐的地址:Latlng ->地址谷歌地图