2014-03-06 3 views

답변

13

Google지도는 기하 도형 라이브러리에 spherical functions이라는 편리한 세트를 가지고있어서 정말 쉽습니다.

지정된 호 (시계 북쪽에서도 표현됨)의 원점으로부터의 거리를 이동하는 결과를 반환하는 LatLng : 즉, 우리가 원하는 기능 computeOffset.

우리는 원점 (원의 중심)과 거리 (원의 반지름)가 있으므로 원하는면의 수를 기준으로 점의 표제를 계산하면됩니다.

function generateGeoJSONCircle(center, radius, numSides){ 

    var points = [], 
     degreeStep = 360/numSides; 

    for(var i = 0; i < numSides; i++){ 
    var gpos = google.maps.geometry.spherical.computeOffset(center, radius, degreeStep * i); 
    points.push([gpos.lng(), gpos.lat()]); 
    }; 

    // Duplicate the last point to close the geojson ring 
    points.push(points[0]); 

    return { 
    type: 'Polygon', 
    coordinates: [ points ] 
    }; 
} 

geometry library은 기본적으로 포함되어 있지 않습니다. libraries parameter을 통해 구체적으로 요청해야합니다.

관련 문제