我点击按钮后尝试在谷歌地图中插入标记。实际上我已将参数传递给addmarker()函数。仍然没有显示标记。我提供了我的源代码。
function initialize() {
var myLatlng = new google.maps.LatLng(23.684994000000000000, 90.356330999999950000);
var mapOptions = {
zoom: 4,
center: myLatlng
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
}
function addmarker(Clientlatitude, Clientlongitude) {
var latilongi = new google.maps.LatLng(Clientlatitude, Clientlongitude);
var marker = new google.maps.Marker({
position: latilongi,
map: this
});
}
google.maps.event.addDomListener(window, 'load', initialize);
<input id="btnMarkerInseart" type="button" value="Insert" onclick='<%# "addmarker(" +Eval("latitude") + ", " +Eval("longitude") + ");" %>' />
答案 0 :(得分:0)
你应该在初始化函数之外声明你的map变量,然后在创建标记时在你的addmarker函数中引用它,如下所示:
var map;
function initialize() {
var myLatlng = new google.maps.LatLng(23.684994000000000000, 90.356330999999950000);
var mapOptions = {
zoom: 4,
center: myLatlng
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
}
function addmarker(Clientlatitude, Clientlongitude) {
var latilongi = new google.maps.LatLng(Clientlatitude, Clientlongitude);
var marker = new google.maps.Marker({
position: latilongi,
map: map
});
}