本文介绍了我怎样才能做一个gmap v3与多个标记,这些是可拖动的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  var marker = new google.maps.Marker({
position:myLatLng,
map:map,
icon:image,
title:tittle,
zIndex:i,
draggable:true
});

google.maps.event.addListener(marker,'drag',function(){
$(input [name ='request'])。val(marker.getPosition ));
});

google.maps.event.addListener(marker,'dragend',function(){
$(input [name ='request'])。val(marker.getPosition( ));
});

事件被添加到单个标记中,并且需要至少有1000个甚至无限。

解决方案

使用数组的位置并为每个位置调用addMarker方法。

  var locationsArray; 

for(var i = 0; i< locationsArray.length; i ++){
addMarker(locationsArray [i]);



函数addMarker(myLatLng){
var marker = new google.maps.Marker({
position:myLatLng,
map:map,
icon:image,
title:tittle,
zIndex:i,
draggable:true
});

google.maps.event.addListener(marker,'drag',function(){
$(input [name ='request'])。val(marker.getPosition ));
});

google.maps.event.addListener(marker,'dragend',function(){
$(input [name ='request'])。val(marker.getPosition( ));
});
}


var marker = new google.maps.Marker({
    position: myLatLng,
    map: map,
    icon: image,
    title: tittle,
    zIndex: i,
    draggable: true
});

google.maps.event.addListener(marker, 'drag', function() {
    $("input[name='request']").val(marker.getPosition());
});

google.maps.event.addListener(marker, 'dragend', function() {
    $("input[name='request']").val(marker.getPosition());
});

the event is added to a single marker and need to be for many at least 1000 or even infinite.

解决方案

use array of positions and for each position call addMarker method.

var locationsArray;

for(var i = 0 ; i<locationsArray.length; i++){
    addMarker(locationsArray[i]);
}


function addMarker(myLatLng){
var marker = new google.maps.Marker({
    position: myLatLng,
    map: map,
    icon: image,
    title: tittle,
    zIndex: i,
    draggable: true
});

google.maps.event.addListener(marker, 'drag', function() {
    $("input[name='request']").val(marker.getPosition());
});

google.maps.event.addListener(marker, 'dragend', function() {
    $("input[name='request']").val(marker.getPosition());
});
}

这篇关于我怎样才能做一个gmap v3与多个标记,这些是可拖动的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 21:45