[英]ASP google map add marker on button click
我有一个 asp gridview,在该按钮上单击按钮字段列我需要通过获取单击的行值(经度和纬度)在 Google map 上添加一个点。 I have written a javascript function for this and I have called that function on OnClientClick but the problem is I dont know how to pass long and latt to that function. 我曾尝试使用隐藏字段,但新的 google.maps.LatLng() 采用双精度值,因此无法正常工作。 这是我的 javascript function,
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 行按钮时,我想传递它们。
您在每次点击时创建一个新的 google.maps.Map - 可能不是您想要做的。 在页面加载时在别处创建 map,并使用您在此处分配的“mao”变量添加标记。
如果这没有帮助,请发布有关您所看到内容的更多信息 - 错误消息等。
谢谢大家,我找到了解决方案。 我在更新面板中添加了一个按钮,然后我在该按钮上调用了我的 javascript function 点击这里是按钮点击代码,
string lat = "-25.363882";
string longt = "131.044922";
ScriptManager.RegisterStartupScript(this,this.GetType(),
"addDoctorLocation",
"addDoctorLocation(" + lat + "," + longt + ")", true);
addDoctorLocation() 是我的 javascript function 需要很长时间,latt 并在我的 map 上添加一个点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.