1

即使對於大師似乎這樣也許太困難,所以我會嘗試重新說出它來嘗試獲得一些迴應: 我想添加一個頂點或頂點到現有的多邊形智能無交叉或自相交,但我能找到的是以下複雜的V2例子: http://www.kashey.ru/pages/maps/basic_poly_editor_test.php# 我想做同樣的事情,但用Google Maps API V3代替。 有沒有人知道檢測哪個現存的多邊形邊或多邊形邊距離您在該多邊形附近點擊的點最近或最近的方法? 我相信這需要一些嚴肅的數學和trig函數,但到目前爲止我找不到任何使用Google Maps API的人。 也許如果有人能告訴我如何將上面的V2代碼轉換爲V3,那麼我可以運行它。 任何幫助將非常感激。谷歌地圖API v3添加新的多邊形頂點沒有交叉或自相交

回答

0

試試這個:

<html> 
<head> 
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3&sensor=false"></script> 
</head> 
<body> 
<div id="map-canvas" style="width: 100%; height: 100%; margin: 0; padding: 0;">map</div> 
<script type="text/javascript"> 
    google.maps.event.addDomListenerOnce(window, 'load', function initialize() { 
    var container = document.getElementById('map-canvas'); 
    var map = new google.maps.Map(container, { 
     center: new google.maps.LatLng(37.4419, -122.1419), 
    zoom: 13 
    }); 


    var vertexes = [ 
     new google.maps.LatLng(37.4419  , -122.1419), 
     new google.maps.LatLng(37.4419+0.03, -122.1419), 
     new google.maps.LatLng(37.4419  , -122.1419+0.03) 
    ]; 

    var polygon = new google.maps.Polygon({ 
     paths: vertexes, 
     editable: true, 
     map: map 
    }); 
    }); 
</script> 
</body> 
</html>