Javascript 很难在谷歌地图上找到某个区域内的位置
我在谷歌地图上画了一个多边形。但我无法验证该区域内是否存在一个点。我怎样才能做到这一点?如有任何建议,将不胜感激Javascript 很难在谷歌地图上找到某个区域内的位置,javascript,html,google-maps-api-3,dom-events,Javascript,Html,Google Maps Api 3,Dom Events,我在谷歌地图上画了一个多边形。但我无法验证该区域内是否存在一个点。我怎样才能做到这一点?如有任何建议,将不胜感激 <!DOCTYPE html> <html> <head> <title>Polygon</title> <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=my_API_key&sens
<!DOCTYPE html>
<html>
<head>
<title>Polygon</title>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=my_API_key&sensor=false&libraries=geometry"></script>
<script>
var centerPoint = new google.maps.LatLng(22.65, 88.45);
var centerPoint2 = new google.maps.LatLng(28.3, 86.3167);
var centerPoint3 = new google.maps.LatLng(22.65, 88.45);
var centerPoint4 = new google.maps.LatLng(20.6333, 84.3167);
var centerPoint5 = new google.maps.LatLng(24.6333, 85.3167);
function Initialize() {
var mapProp = {
center: centerPoint,
zoom: 4,
mapTypeId: google.maps.MapTypeId.HYBRID
};
var map = new google.maps.Map(document.getElementById("MyMap"), mapProp);
var marker = new google.maps.Marker({
position: centerPoint,
animation: google.maps.Animation.BOUNCE
});
var myTrip = [centerPoint2, centerPoint3, centerPoint4];
var flightPath = new google.maps.Polygon({
path: myTrip,
strokeColor: "#0000FF",
strokeOpacity: 0.2,
strokeWeight: 2,
fillColor: "#B0F0FF",
fillOpacity: 0.4,
editable: true
});
marker.setMap(map);
flightPath.setMap(map);
var locationExists = new google.maps.geometry.poly.containsLocation({
point: centerPoint5,
polygon: flightPath
});
document.getElementById("MyData").innerHTML = locationExists;
}
google.maps.event.addDomListener(window, 'load', Initialize);
</script>
</head>
<body>
<div id="MyMap" style="height: 500px; width: 500px;"></div>
<div id="MyData" style="height: 500px; width: 500px;"></div>
</body>
多边形
var centerPoint=newgoogle.maps.LatLng(22.65,88.45);
var centerPoint2=新的google.maps.LatLng(28.3,86.3167);
var centerPoint3=新的google.maps.LatLng(22.65,88.45);
var centerPoint4=新的google.maps.LatLng(20.633384.3167);
var centerPoint5=新的google.maps.LatLng(24.6333,85.3167);
函数初始化(){
var mapProp={
中心:中心点,
缩放:4,
mapTypeId:google.maps.mapTypeId.HYBRID
};
var map=new google.maps.map(document.getElementById(“MyMap”),mapProp);
var marker=new google.maps.marker({
位置:中心点,
动画:google.maps.animation.BOUNCE
});
var myTrip=[centerPoint2,centerPoint3,centerPoint4];
var flightPath=new google.maps.Polygon({
路径:myTrip,
strokeColor:#0000FF“,
笔划不透明度:0.2,
冲程重量:2,
填充颜色:“B0F0FF”,
填充不透明度:0.4,
可编辑:真
});
marker.setMap(map);
flightPath.setMap(map);
var locationExists=new google.maps.geometry.poly.containsLocation({
点:中心点5,
多边形:飞行路径
});
document.getElementById(“MyData”).innerHTML=locationExists;
}
google.maps.event.addDomListener(窗口“加载”,初始化);
containsLocation()
是否正确使用?如果没有,请建议
使用
注意:默认情况下不会加载几何体库,您必须使用maps api的libraries参数来加载几何体库
注意:默认情况下不加载几何体库,您必须使用maps api的libraries参数来加载几何体库containsLocation(point:LatLng,polygon:polygon),在这里,我应该在polygon中提供什么:???部分?google.maps.Polygon-object,您要在其中检测点是否在,请创建一个您的尝试,如果没有任何代码oops,这是无法帮助的!是的,对不起。我…只是等待一个li'l。错误:对象不支持属性或方法“lng”包含位置(点:LatLng,多边形:polygon)在这里,我应该在多边形中提供什么:???部分?google.maps.Polygon-object,您要在其中检测点是否在,请创建一个您的尝试,如果没有任何代码oops,这是无法帮助的!是的,对不起。我…等一下。错误:对象不支持属性或方法“lng”。虽然图像不一样。但是想法是。虽然图像不一样。但是想法是。