2014-09-23 34 views
0

我試圖在用戶移動時在位置數據的地圖上繪製多邊形。我不希望多邊形之間有任何中斷。我需要下一個多邊形的一側連接到前一個多邊形的一側。我會怎麼做呢?我有迄今爲止所做的,但我不確定如何收集位置數據並使用之前的數據來連接多邊形。連接多邊形邊與位置數據

我使用:

onLocationChanged(Location location) { 
    currentLocation = (new LatLng(location.getLatitude(), location.getLongitude())); 
    if(previousLocation != null) { 
     polygonCornerBackLeftCorner = SphericalUtil.computeOffset(currentLocation, widthInMeters/2, location.getBearing() + 90); 
     polygonCornerBackRightCorner = SphericalUtil.computeOffset(currentLocation, widthInMeters/2, location.getBearing() + 90); 
    } 
    previousLocation = currentLocation 
} 

polygonGenerator() { 
    PolygonOptions polygon = new PolygonOptions().add(polygonCornerBackLeftCorner,  polygonCornerBackRightCorner, polygonCornerFrontRight, polyCornerFrontLeft).fillColor(Color.YELLOW); 
    getMap().addPolygon(whatsquare); 
} 

回答

0

每當你得到一個新的currentLocation,你要計算對應於它的角點,你要對它們進行緩存供以後使用。如果這不是第一個位置,那麼您將擁有一對緩存的角點,然後您將使用它們加上新角色來製作多邊形並將其添加到地圖中,然後緩存新角點下一次迭代。