Which type of result needed 我需要在Google地图中的多边形内找到所有位置。我必须编写代码以绘制自由手绘多边形,但不知道如何找到所选区域内的所有地点,例如餐厅,酒吧,医院等。
<!DOCTYPE html>
<html>
<head>
<title>Drawing Tools</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
position: inherit!important;
width:550px !important;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map_canva>div {
top: 98px !important;
}
</style>
</head>
<body>
<div id="drawpoly"><a href="#">Click Here To Draw On Map</a></div>
<br/>
<div id="map_canva"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://maps.googleapis.com/maps/api/js?libraries=geometry,places&key=API_Key"></script>
<script>
function drawFreeHand() {
//the polygon
poly = new google.maps.Polyline({ map: map, clickable: false });
//move-listener
var move = google.maps.event.addListener(map, 'mousemove', function (e) {
poly.getPath().push(e.latLng);
});
//mouseup-listener
google.maps.event.addListenerOnce(map, 'mouseup', function (e) {
google.maps.event.removeListener(move);
var path = poly.getPath();
poly.setMap(null);
poly = new google.maps.Polygon({ map: map, path: path });
google.maps.event.clearListeners(map.getDiv(), 'mousedown');
enable()
});
<!-- google.maps.event.addListener(map, 'click', function (e) { -->
<!-- var path = poly.getPath(); -->
<!-- poly = new google.maps.Polygon({ map: map, path: path }); -->
<!-- alert(poly); -->
<!-- }); -->
}
function disable() {
map.setOptions({
draggable: false,
zoomControl: false,
scrollwheel: false,
disableDoubleClickZoom: false
});
}
function enable() {
map.setOptions({
draggable: true,
zoomControl: true,
scrollwheel: true,
disableDoubleClickZoom: true
});
}
function initialize() {
var mapOptions = {
zoom: 14,
center: new google.maps.LatLng(52.549878, 13.425209),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canva'), mapOptions);
//draw
$("#drawpoly a").click(function (e) {
e.preventDefault();
disable()
google.maps.event.addDomListener(map.getDiv(), 'mousedown', function (e) {
drawFreeHand()
});
});
}
google.maps.event.addDomListener(window, 'load', initialize)
</script>
</body>
</html>
我需要找到所选区域内的所有地方,例如餐厅,酒吧,医院等。