【发布时间】:2011-10-06 17:28:48
【问题描述】:
我有一个带有按钮字段列的 asp gridview,单击该按钮我需要通过获取单击的行值(经度和纬度)在 Google 地图上添加一个点。我为此编写了一个 javascript 函数,并在 OnClientClick 上调用了该函数,但问题是我不知道如何将 long 和 latt 传递给该函数。我曾尝试使用隐藏字段,但新的 google.maps.LatLng() 采用双精度值,因此无法正常工作。这是我的javascript函数,
function addDoctorLocation()
{
var lat = document.getElementById('<%= hfLong.ClientID %>').value;
var longt = document.getElementById('<%= hfLong.ClientID %>').value;
var myLatlng = new google.maps.LatLng(parseFloat(document.getElementById('<%= hfLong.ClientID %>').value), parseFloat(document.getElementById('<%= hfLong.ClientID %>').value));
var myOptions = {
zoom: 10,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var marker = new google.maps.Marker({
position: myLatlng,
title:"Hello World!"
});
// To add the marker to the map, call setMap();
marker.setMap(map);
}
和我的 asp 代码(这里我没有 gridview 只是一个按钮,我希望在 gridview RowCommand 事件上分配隐藏字段值。),
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Button"
OnClientClick="addDoctorLocation()" onclick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
请有人帮我解决这个问题。当我在 javascript 中硬编码经度和纬度值时,此解决方案有效。但我想在用户点击 gridview 行按钮时传递它们。
【问题讨论】:
-
这可能与您的问题无关,但我注意到您在 lat 和 long 中都使用了 hfLong 的值。
-
是的 Ray 我正在为页面加载时的两个隐藏字段分配值,这只是为了测试目的,在这里我只添加了一个按钮而不是 gridview 我希望在 gridview RowCommand 事件中分配这些值.
-
您只使用了一个隐藏字段的值来表示纬度和经度。这不会在地图上标出您认为应该去的地方。
标签: javascript asp.net google-maps google-maps-markers