Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在谷歌地图上刷新和删除标记_Javascript_Jquery_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 在谷歌地图上刷新和删除标记

Javascript 在谷歌地图上刷新和删除标记,javascript,jquery,google-maps,google-maps-api-3,Javascript,Jquery,Google Maps,Google Maps Api 3,我是谷歌地图功能的新手,我想知道如何删除地图上的标记,刷新地图会不会删除标记,或者我是否需要添加一些东西来删除标记 我使用数据库中的Getjson循环添加标记 这是我的代码集 var Rad = 0; var customerlocationID = 0; var geocoder, infoBubble, geocode; var map; var selectedMarker; var ID; //var mgr; $("#ddlRadius").live("change", functi

我是谷歌地图功能的新手,我想知道如何删除地图上的标记,刷新地图会不会删除标记,或者我是否需要添加一些东西来删除标记

我使用数据库中的Getjson循环添加标记

这是我的代码集

var Rad = 0;
var customerlocationID = 0;

var geocoder, infoBubble, geocode;
var map;
var selectedMarker;
var ID;
//var mgr;
$("#ddlRadius").live("change", function () {
    var selectValue = "";
    selectValue = $("#ddlRadius option:selected").val();

    if (selectValue == "77") {
        Rad = 5;
        codeAddress(customerlocationID, Rad);
    } else if (selectValue == "78") {
        Rad = 10;
        codeAddress(customerlocationID, Rad);
    } else if (selectValue == "79") {
        Rad = 25;
        codeAddress(customerlocationID, Rad);
    } else if (selectValue == "80") {
        Rad = 50;
        codeAddress(customerlocationID, Rad);
    } else if (selectValue == "81") {
        Rad = 100;
        codeAddress(customerlocationID, Rad);
    }
});


function initialize() {
    var minZoomLevel = 4;
    var zooms = 7;
    geocoder = new google.maps.Geocoder();
    geocode = new google.maps.Geocoder();

    // Used to Set the Center of the Maps on the Logged User
    $.getJSON('/Dashboard/LoadAddress', function Geocoding(address) {
        $.each(address, function () {
            customerlocationID = this["ID"];
            var currValAddress = this["AddressLine1"];
            var Latitude = this["Latitude"];
            var Longitude = this["Longitude"];
            var LatLang = new google.maps.LatLng(Latitude, Longitude);
            var addresse = {
                zoom: 8,
                center: LatLang,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            map = new google.maps.Map(document.getElementById('map'), addresse);


            // Bounds for North America
            var strictBounds = new google.maps.LatLngBounds(
            new google.maps.LatLng(15.70, -160.50),
            new google.maps.LatLng(68.85, -55.90));

            // Listen for the dragend event
            google.maps.event.addListener(map, 'dragend', function () {
                if (strictBounds.contains(map.getCenter())) return;
                // We're out of bounds - Move the map back within the bounds

                var c = map.getCenter(),
                    x = c.lng(),
                    y = c.lat(),
                    maxX = strictBounds.getNorthEast().lng(),
                    maxY = strictBounds.getNorthEast().lat(),
                    minX = strictBounds.getSouthWest().lng(),
                    minY = strictBounds.getSouthWest().lat();

                if (x < minX) x = minX;
                if (x > maxX) x = maxX;
                if (y < minY) y = minY;
                if (y > maxY) y = maxY;

                map.setCenter(new google.maps.LatLng(y, x));
            });

            // Limit the zoom level
            google.maps.event.addListener(map, 'zoom_changed', function () {
                if (map.getZoom() < minZoomLevel) map.setZoom(minZoomLevel);
            });
        });
    });
    codeAddress(customerlocationID, Rad);
}

var iconBase = 'https://maps.google.com/mapfiles/kml/shapes/';

function codeAddress(customerlocationID, Rad) {
    infoBubble = new InfoBubble({
        map: map,
        shadowStyle: 0,
        padding: 10,
        borderRadius: 10,
        arrowSize: 15,
        maxWidth: 300,
        borderWidth: 1,
        borderColor: '#ccc',
        arrowPosition: 50,
        arrowStyle: 0
    });
    $.getJSON('/Dashboard/LoadWorkerList1' + '?customerLocationID=' + customerlocationID + '&radius=' + Rad, function Geocode(addresses) {
        $.each(addresses, function () {
            var currVal = this["AddressLine1"];
            var Name = this["Name"];
            var Gender = this["Gender"];
            var Bdate = this["Birthdate"];
            ID = this["Worker_ID"];
            var distance = this["Distance"];
            var workerDetailIDDD = this["Worker_ID"];
            var Latitude = this["Latitude"];
            var Longitude = this["Longitude"];
            var LatLang = new google.maps.LatLng(Latitude, Longitude);

            var marker = new google.maps.Marker({
                map: map,
                icon: '/Content/images/male.png',
                position: LatLang,
                title: currVal
            })

            var link = $('<a href="#">' + currVal + '</a>').data('location', LatLang);
            $('#places').append($('<li id=\'List\' class=\'List\'>').append(link));
            link.on('click', function (event) {
                event.preventDefault();
                google.maps.event.trigger(addresses[0], "click");
                if (selectedMarker) {
                    selectedMarker.setIcon('/Content/images/male.png');
                }
                marker.setIcon('/Content/images/maleclicked.png');
                selectedMarker = marker;
                infoBubble.removeTab(0);
                infoBubble.addTab(Name, "Name: " + Name + "<br> Address: " + currVal + "<br> Gender: " + Gender + "<br> Birthdate: " + Bdate + "<br> Distance: " + distance + "<br><br>" + '<center><a href="/Dashboard/WorkerMapDetail?workerId=' + workerDetailIDDD + '" onclick="window.open(this.href,height=850,width=1200);return false""><span style="font-size: 12px !important">View Profile</span></a></center>');
                infoBubble.open(map, marker);
            });


            google.maps.event.addListener(map, 'idle', function () {
                $('#places li').each(function () {
                    var inside = (map.getBounds().contains($(this).find('a').data('location'))) ? '' : 'none';
                    $(this).css('display', inside);
                });
            });

            // Listen for user click on map to close any open info bubbles
            google.maps.event.addListener(map, "click", function () {
                infoBubble.close();
                marker.setIcon('/Content/images/male.png');
            });

            google.maps.event.addListener(map, "dragstart", function () {
                infoBubble.close();
                marker.setIcon('/Content/images/male.png');
            });
            google.maps.event.addListener(marker, 'click', (function (marker, i) {
                return function () {
                    if (selectedMarker) {
                        selectedMarker.setIcon('/Content/images/male.png');
                    }
                    marker.setIcon('/Content/images/maleclicked.png');
                    selectedMarker = marker;
                    infoBubble.removeTab(0);
                    infoBubble.addTab(Name, "Name: " + Name + "<br> Address: " + currVal + "<br> Gender: " + Gender + "<br> Birthdate: " + Bdate + "<br> Distance: " + distance + "<br><br>" + '<center><a href="/Dashboard/WorkerMapDetail?workerId=' + workerDetailIDDD + '" onclick="window.open(this.href,height=850,width=1200);return false""><span style="font-size: 12px !important">View Profile</span></a></center>');
                    infoBubble.open(map, marker);
                }
            })(marker, currVal));
        })
        google.maps.event.trigger(map, 'bounds_changed');
    })
}
window.onload = function () {
    initialize();
}
var-Rad=0;
var customerlocationID=0;
var geocoder、infoBubble、geocode;
var映射;
var选择标记;
变量ID;
//风险经理;
$(“#ddlRadius”).live(“更改”,函数(){
var selectValue=“”;
selectValue=$(“#ddlRadius选项:选中”).val();
如果(选择值=“77”){
Rad=5;
代码地址(customerlocationID,Rad);
}else if(selectValue==“78”){
Rad=10;
代码地址(customerlocationID,Rad);
}else if(selectValue==“79”){
Rad=25;
代码地址(customerlocationID,Rad);
}否则如果(selectValue==“80”){
Rad=50;
代码地址(customerlocationID,Rad);
}else if(selectValue==“81”){
Rad=100;
代码地址(customerlocationID,Rad);
}
});
函数初始化(){
var minZoomLevel=4;
变焦值=7;
geocoder=新的google.maps.geocoder();
geocode=新的google.maps.Geocoder();
//用于设置登录用户的地图中心
$.getJSON('/Dashboard/LoadAddress',函数地理编码(地址){
$。每个(地址、函数(){
customerlocationID=此[“ID”];
var currValAddress=此[“AddressLine1”];
var纬度=此[“纬度”];
var经度=此[“经度”];
var LatLang=new google.maps.LatLng(纬度、经度);
变量地址={
缩放:8,
中心:拉特朗,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
map=新的google.maps.map(document.getElementById('map'),地址);
//前往北美的边界
var strictBounds=new google.maps.LatLngBounds(
新google.maps.LatLng(15.70,-160.50),
新google.maps.LatLng(68.85,-55.90));
//收听dragend事件
google.maps.event.addListener(映射'dragend',函数(){
if(strictBounds.contains(map.getCenter())返回;
//我们超出边界-将地图移回边界内
var c=map.getCenter(),
x=c.lng(),
y=c.lat(),
maxX=strictBounds.getNorthEast().lng(),
maxY=strictBounds.getNorthEast().lat(),
minX=strictBounds.getSouthWest().lng(),
minY=strictBounds.getsoutwest().lat();
如果(xmaxX)x=maxX;
如果(ymaxY)y=maxY;
map.setCenter(新的google.maps.LatLng(y,x));
});
//限制缩放级别
google.maps.event.addListener(映射'zoom_changed',函数(){
if(map.getZoom()').append(link));
link.on('click',函数(事件){
event.preventDefault();
google.maps.event.trigger(地址[0],“单击”);
如果(已选择标记){
选择marker.setIcon('/Content/images/male.png');
}
setIcon('/Content/images/maleclicted.png');
selectedMarker=标记器;
infoBubble.removeTab(0);
infoBubble.addTab(姓名,姓名:“+Name+”
地址:“+currVal+”
性别:“+Gender+”
出生日期:“+Bdate+”
距离:“+Distance+”

”+”; 打开(地图、标记); }); google.maps.event.addListener(映射'idle',函数(){ $('#places li')。每个(函数(){ var inside=(map.getBounds().contains($(this.find('a'))。data('location'))?“”:“无”; $(this.css('display',inside)); }); }); //听用户点击地图关闭任何打开的信息气泡 google.maps.event.addListener(映射,“单击”,函数(){ infoBubble.close(); setIcon('/Content/images/male.png'); }); google.maps.event.addListener(映射,“dragstart”,函数(){ 信息泡沫。
marker.setMap(null);
$.each(markers, function() {
    this.setMap(null);
});