如何在谷歌地图上删除外部元素的坐标?

时间:2016-06-22 11:04:37

标签: javascript jquery google-maps jquery-ui

我有一个谷歌地图和一个自定义元素用作标记。当我从地图上的地图外面放下标记时,我需要获取该位置的坐标。这该怎么做? " .clue_bottom_left img"是用作标记的元素。

使用jquery-ui拖放代码:



	 $(".clue_bottom_left img").draggable({
		containment: 'map',
		revert: "invalid",
		start: function(evt, ui) {
			$('.clue_bottom_left img').fadeTo('fast', 0.6, function() {});
		},
		stop: function(evt, ui) {
			$('.clue_bottom_left img').fadeTo('fast', 1.0, function() {});
			// INSERT Point
		}
	});
	$('#map').droppable({
        drop: function(e, ui) {
            $(ui.draggable).draggable();
        }
    });




创建地图的代码:



function initAutocomplete() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 41.9876644, lng: 22.4192234},
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: true, // a way to quickly hide all controls
});

// Create the search box and link it to the UI element.
var input = document.getElementById('pac-input');
var searchBox = new google.maps.places.SearchBox(input);
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

// Bias the SearchBox results towards current map's viewport.
map.addListener('bounds_changed', function() {
searchBox.setBounds(map.getBounds());
});

var markers = [];
// Listen for the event fired when the user selects a prediction and retrieve
// more details for that place.
searchBox.addListener('places_changed', function() {
var places = searchBox.getPlaces();

if (places.length == 0) {
return;
}

// Clear out the old markers.
markers.forEach(function(marker) {
marker.setMap(null);
});
markers = [];

// For each place, get the icon, name and location.
var bounds = new google.maps.LatLngBounds();
places.forEach(function(place) {
var icon = {
url: place.icon,
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(25, 25)
};
						
// Create a marker for each place.
markers.push(new google.maps.Marker({
map: map,
icon: icon,
title: place.name,
position: place.geometry.location
}));

if (place.geometry.viewport) {
// Only geocodes have viewport.
bounds.union(place.geometry.viewport);
} else {
bounds.extend(place.geometry.location);
}
});
map.fitBounds(bounds);
});
}




更新 这不是重复的,因为当标记被放置在地图上时,有人用另一篇文章标记了如何做某事。我知道该怎么做。我的标记实际上不是标记。是地图外的div中的图像。我想知道如何使用jQuery UI拖放来使用该图像作为标记。

0 个答案:

没有答案