我想查看錶單提供的緯度和經度座標是否在多邊形內,然後提醒用戶兩個實例。點對多維數據集檢查緯度和經度值
到目前爲止,這裏是我的代碼。我已經做了一些研究,據說您可以使用光線投射,或者您可以使用Google Maps API提供的containsLocation()來執行此操作。但我無法弄清楚如何使用它來實現。
這裏是一個演示http://codepen.io/simonfricker/pen/qbxOxy
HTML
<input id="location" placeholder="" type="text" class="form-control" autocomplete="off">
<div id="map"></div>
JS
var option = {
types: ['(cities)'],
// country: 'GB'
};
var latco, lngco;
$("#location").geocomplete(option).bind("geocode:result", function(event, result) {
latco = result.geometry.location.lat()
lngco = result.geometry.location.lng()
console.log(result.geometry.location.lng());
console.log(result.geometry.location.lat());
});
var map;
var src = 'http://kml-samples.googlecode.com/svn/trunk/kml/Region/polygon-simple.kml';
function initialize() {
map = new google.maps.Map(document.getElementById('map'), {
center: new google.maps.LatLng(-19.257753, 146.823688),
zoom: 2,
mapTypeId: google.maps.MapTypeId.TERRAIN
});
loadKmlLayer(src, map);
}
function loadKmlLayer(src, map) {
var kmlLayer = new google.maps.KmlLayer(src, {
suppressInfoWindows: true,
preserveViewport: false,
map: map
});
google.maps.event.addListener(kmlLayer, 'click', function(event) {
var content = event.featureData.infoWindowHtml;
var testimonial = document.getElementById('capture');
testimonial.innerHTML = content;
});
}
google.maps.event.addDomListener(window, 'load', initialize);
的[標記確定的多邊形內的LAT LNGS]可能的複製(http://stackoverflow.com/questions/2784807/determine-the - 多邊形內的標記點) – Pio
您無法訪問使用KmlLayer顯示的KML文件中的多邊形數據,您需要將該多邊形創建爲本地Google Maps JavaScript API v3多邊形。您可以使用第三方KML解析器,如[geoxml3](https://github.com/geocodezip/geoxml3)或[geoxml-v3](https://code.google.com/p/geoxml-v3/ )。 – geocodezip