2

我在谷歌地图上使用了淘汰赛 javascrit,但我无法清除地图上的标记,我在那里收到错误消息,错误如下

> Ripple :: Environment Warming Up (Tea. Earl Gray. Hot.) ripple.js:37
> web :: Initialization Finished (Make it so.) ripple.js:37 Uncaught
> TypeError: Object [object Object] has no method 'dxmap' Shops.js:70
> eula response:  true ripple.js:47 Uncaught TypeError: Object [object
> Object] has no method 'dxmap' Shops.js:70 Uncaught TypeError: Object
> #<Object> has no method 'setMap' Shops.js:137

我下面的代码你能帮帮我吗

function FetchNearestShops(latitud,longitud)
    {
        $.ajax({
            type: 'POST',
            async:false,
            contentType: 'application/json',
            dataType: 'jsonp',
            url: url + "/GetNearestShop",
            //data: { Latitude: 9.998472, Longitude: 76.308059 },
            data: { Latitude: latitud, Longitude: longitud },
            success: function (data) {                
                loc.removeAll();
                productsNear.removeAll();
                $.map(data, function (item) {
                    loc.push({ label: item.ShopName, location: [item.Latitude, item.Longitude] });
                    //productsNear.push({ Name: item.ShopName, IsFavorite: false, Address: "", id: item.ShopId, Image: "mockcontent/shopimages/1.jpg" });
                    productsNear.push({ Name: item.ShopName, IsFavorite: item.Isfavourite, Address: item.Address, id: item.ShopId, Image: item.ImageUrl });
                });
                alert();
                viewModel.options.markers = loc;

            },
            error: function () {
                alert("error");
            }

        });
    }
    function SetLocation() {
        var geocoder = new google.maps.Geocoder();
        //var address = "ernakulam";
        //alert(viewModel.options.location());
        geocoder.geocode({ 'address': txtAddress() }, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                var latitude = results[0].geometry.location.lat();
                var longitude = results[0].geometry.location.lng();
                ClearMap();

                FetchNearestShops(latitude, longitude);
            }
        });
    }
    function ClearMap()
    {
        var markers = viewModel.options.markers();
        for (var i = 0; i < markers.length; i++) {
            markers[i];
            markers.setMap(null);
        }
        markers;


    } 
4

1 回答 1

3

我认为你的ClearMap()函数循环有问题。尝试

for (var i = 0; i < markers.length; i++) {
    markers[i].setMap(null);
}

相反markers.setMap(null);。我也不确定你markers的谷歌标记集合是正确的。此集合应如下所示:

markers[i] = new google.maps.Marker({
        position: new google.maps.LatLng('some latitude', 'some longitude'),
        map: map, //object of Google Map
        name: 'Marker Name'
    });
于 2013-11-14T08:41:43.667 回答