2011-10-31 2 views
1

저는 사람들이 Google지도에서 사각형을 그리고 bottomLeft 및 topRight 좌표를 저장할 수있게하려고합니다. 내가 직사각형 codewise을 그릴 수 있습니다 알고Google지도로 지오 펜싱

(참조 : http://code.google.com/intl/nl-NL/apis/maps/documentation/javascript/reference.html#Rectangle을),하지만 난 내 DB에서 경계를로드 할 수 있습니다 전에 사람들은 스스로가 그것을 정의 할 필요가 첫째 과정 :

그래서 제 질문은, 어떻게 사람들이 Google지도 (API v3)에 사각형을 그리고 bottomLeft 및 topRight 모서리의 좌표를 저장할 수있게 할 수 있습니까?

답변

3

이미 이벤트를 조사하여 작동하도록했습니다. 내 시간을 많이 만들하는 데 걸린 :)

이 내가 그것을 필요로하는 사람을 위해 일을 한 방법입니다

function mapsInitialize() 
{ 
    startPoint = new google.maps.LatLng(lat,lon); 
    options = { zoom: 16, center: startPoint, mapTypeId: google.maps.MapTypeId.HYBRID}; 
    map = new google.maps.Map(document.getElementById("map_canvas"), options); 


    google.maps.event.addListener(map, 'click', function(event) { 
     if (drawing == true){ 
      placeMarker(event.latLng); 
      if (bottomLeft == null) { 
       bottomLeft = new google.maps.LatLng(event.latLng.Oa, event.latLng.Pa); 
      } 
      else if (topRight == null){ 
       topRight = new google.maps.LatLng(event.latLng.Oa, event.latLng.Pa); 
       drawing = false; 
       rectangle = new google.maps.Rectangle(); 

       var bounds = new google.maps.LatLngBounds(bottomLeft, topRight); 

       var rectOptions = { 
        strokeColor: "#FF0000", 
        strokeOpacity: 0.8, 
        strokeWeight: 2, 
        fillColor: "#FF0000", 
        fillOpacity: 0.35, 
        map: map, 
        bounds: bounds 
       }; 
       rectangle.setOptions(rectOptions); 
      } 
     } 
    }); 
} 

function placeMarker(location) { 
    var marker = new google.maps.Marker({ 
     position: location, 
     map: map 
    }); 
} 
2

제대로 이해한다면 - 사용자가 폴리 라인/폴리곤을 입력하게하는 방법이 필요합니다. 그렇다면 example을보고지도를 클릭하여 다각형을 만듭니다. 그것은 어떤 클래스의 PolygonCreator와 jquery를 사용합니다. 이 메소드를 채택하고 결과를 양식 필드에 저장할 수 있습니다 (가능한 많은 옵션 : JSON 또는 사용자 고유의 직렬화 메소드)

지도에 폴리곤을 표시하면됩니다. 이점은 geometry.encoding library이고 인코딩 된 폴리선을 데이터베이스에 저장합니다. 또는 공간 쿼리를 사용하려는 경우 (예 : 일부 포인트가 다각형에 속하는지 감지), MySQL spatial extensions, PostGIS 등의 공간 확장을 사용하는 것이 좋습니다. MySQL에서는 폴리 라인을 Polyline 또는 Polygon 유형의 컬럼에 저장할 수 있습니다 이것은 OpenGIS 형식을 기반으로합니다. 솔직히, 여기 stackoverflow 관련 정보의 전체 잔뜩입니다.

관련 문제