当您单击地图1中的任何位置时,会创建新标记并生成多边形 它的工作正常,但现在我的问题是我无法得到的是我的标记来自数据库是否在多边形内部,如何知道它?
<?php include("config.php"); ?>
<?php $result = mysql_query("select * from `googlemaps`"); ?>
<html>
<head>
<title>Google Maps</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var poly, map;
var markers = [];
var path = new google.maps.MVCArray;
function initialize() {
var LatLng = new google.maps.LatLng(23.183, 75.767);
map = new google.maps.Map(document.getElementById("map"), {
zoom: 12,
center: LatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
function createMarker(point, title) {
var infowindow = new google.maps.InfoWindow({
content: "<span style='color:blue;'>"+title+"</span>"
});
var marker = new google.maps.Marker({
position: point,
map: map,
title:title
});
marker.Image ='https://d3szoh0f46td6t.cloudfront.net/public/1626980/small';
google.maps.event.addListener(marker, "click", function() {
infowindow.open(map,marker);
});
return marker;
}
<?php
if(mysql_num_rows($result)>0)
{
while( $data = mysql_fetch_array($result) )
{ ?>
createMarker(new google.maps.LatLng(<?php echo $data['lat']; ?>, <?php echo $data['lon']; ?>), "<?php echo $data['title']; ?>");
<?php }
}
?>
poly = new google.maps.Polygon({
strokeWeight: 3,
fillColor: '#5555FF'
});
poly.setMap(map);
poly.setPaths(new google.maps.MVCArray([path]));
google.maps.event.addListener(map, 'click', addPoint);
}
function addPoint(event) {
path.insertAt(path.length, event.latLng);
var marker = new google.maps.Marker({
position: event.latLng,
map: map,
draggable: true
});
markers.push(marker);
marker.setTitle("#" + path.length);
google.maps.event.addListener(marker, 'click', function() {
marker.setMap(null);
for (var i = 0, I = markers.length; i < I && markers[i] != marker; ++i);
markers.splice(i, 1);
path.removeAt(i);
}
);
google.maps.event.addListener(marker, 'dragend', function() {
for (var i = 0, I = markers.length; i < I && markers[i] != marker; ++i);
path.setAt(i, marker.getPosition());
document.getElementById("abc").innerHTML=path.setAt(i, marker.getPosition());
}
);
}
</script>
</head>
<body style="margin:0px; padding:0px;" onLoad="initialize()">
<div id="map" style="width:500px; height:500px;"></div>
<div id="abc"></div>
</body>
</html>
答案 0 :(得分:0)
你可能会问如何查看这个javascript或php。我不了解这些领域的GIS框架。
大多数空间数据库(如我使用的SQL Server / Postgresql)都提供了可以使用的ST_Contains或ST_Distance等功能。我认为这是OpenGIS规范的一部分。
我想你可能正在使用MYSQL。所以可能只需要搜索一个函数。