2010-08-04 3 views
11

내 응용 프로그램에서 Google지도를 사용하고 있으며 lat/lon 값으로 채워진 데이터베이스가있는 웹 서버가 있습니다. 나는 그들을지도에 표시하고 싶지만, 또한 그들이 서로의 특정 픽셀 거리 내에 있다면 함께 모으고 싶다.위도/경도를 픽셀로 변환하고 뒤로

clusters[]; 
while(count(points)) { 
    cluster[]; 
    point = points.pop(); 
    boundingbox = pixelsToBB(point, pixeldistance, zoomlevel); 
    query = "select * from database where lat > boundingbox.minlat 
      and lat < boundingbox.maxlat and lng > boundingbox.minlng 
      and lng < boundingbox.maxlng"; 
    for (result in executedquery) { 
     cluster[] += result; 
     points.remove(result); 
    } 
    clusters[] += cluster; 
} 

pixelsToBB(point, distance, zoomlevel) { 
    center = convertXY(point, zoomlevel); 
    maxlng = convertToLng(center.X, distance, zoomlevel); 
    minlng = convertToLng(center.X, -distance, zoomlevel); 
    minlat = convertToLat(center.Y, -distance, zoomlevel); 
    maxlat = convertToLat(center.Y, distance, zoomlevel); 
    return boundingbox(maxlng, maxlat, minlng, minlat); 
} 

내 pixelsToBB 기능 필요가 개의 zoomLevel로 무엇을 할 것입니다 :

나는 데이터베이스에서 내 모든 포인트를 검색하면 내가 그림,이 (의사) 같은 것을 할 수 있어야한다? 또는 내 convertToXY, convertToLng 및 convertToLat은 무엇을해야합니까? 나는 이것에 대해 올바른 생각을하고 있는가, 아니면 그것을 할 수있는 더 좋은 방법이 있습니까? 무엇을 검색해야할지 모르겠다. 미안하기 전에 질문을 받았다면.

답변

7

사용하여 Google지도 API v3의 :

var latLng = // your position object here 
var projection = map.getProjection(); 
var bounds = map.getBounds(); 
var topRight = projection.fromLatLngToPoint(bounds.getNorthEast()); 
var bottomLeft = projection.fromLatLngToPoint(bounds.getSouthWest()); 
var scale = Math.pow(2, map.getZoom()); 
var worldPoint = projection.fromLatLngToPoint(latLng); 
return [Math.floor((worldPoint.x - bottomLeft.x) * scale), Math.floor((worldPoint.y - topRight.y) * scale)]; 
7

this page에서 Google Maps API 문서의 일부로이를 수행하는 JavaScript 예제가 있습니다. 마음에 든다면 페이지 소스를보아야합니다. 실제 문서 페이지가 아니라 오히려 예입니다.

관련 문제