2013-03-13 155 views
4

而不是用一個實線圍繞它的多邊形,我想用虛線創建一個,這可能嗎?在谷歌地圖v2上繪製虛線而不是實體

我知道你可以這樣做,當你覆蓋v1覆蓋的onDraw方法,但Overlay類不再存在,所以我怎麼能做到這一點?

+0

http://stackoverflow.com/q/6098947/2110460目前說沒有 – Rafe 2013-03-13 20:58:30

+0

@Rafe這是JavaScript API不是android – tyczj 2013-03-13 21:00:35

+0

我在猜測https://developers.google.com/maps/documentation/javascript/overlays#PolylineSymbols也不會幫助嗎?看起來第一個鏈接有點過時了。 – Rafe 2013-03-13 21:32:30

回答

1

首先,看一看在API https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/model/Polyline

目前尚不可能與V2,但V3的JavaScript API,它已經是,看這裏: https://developers.google.com/maps/documentation/javascript/overlays#PolylineSymbols

但似乎它是可以使用的V3的JavaScript API在Android應用程序,看看這裏: https://developers.google.com/maps/articles/android_v3

也許,這將幫助你

3

這是目前不可能的,但你可能會給予好評這種增強的位置:http://code.google.com/p/gmaps-api-issues/issues/detail?id=4633

UPDATE

最近,谷歌實現這一功能在谷歌地圖的Android API v2和顯着的問題,4633折線和多邊形的修正。

查看關於Shapes Guide中的中風模式的信息。查看多義線和多邊形教程中的example

您還可以閱讀相應的博客文章在這裏:

https://maps-apis.googleblog.com/2017/02/styling-and-custom-data-for-polylines.html

1

查找經緯度在從地圖 中心LatLng的半徑單位距離現在將這兩個LatLng轉換爲屏幕座標

使用用於構建cirle X = R SIN(THETA)式中,Y = R COS(THETA)

你劃分圓分成N段,然後繪製在圓周上折線(在地圖上繪製)圈轉換屏幕

多種根據縮放水平更它看起來像一個圓,我已經使用N = 120的數量N,我使用13

private void addDottedCircle(double radius) {//radius is in kms 

    clearDottedCircle(); 


    LatLng center,start,end; 
    Point screenPosCenter,screenPosStart,screenPosEnd; 
    Projection p = mMap.getProjection(); 

    center = searchCenterMarker.getPosition(); 
    start = new LatLng(center.latitude + radius/110.54,center.longitude); 
    // radius/110.54 gives the latitudinal delta we should increase so that we have a latitude at radius distance 
    // 1 degree latitude is approximately 110.54 kms , so the above equation gives you a rough estimate of latitude at a distance of radius distance 


    screenPosCenter = p.toScreenLocation(center); 
    screenPosStart = p.toScreenLocation(start); 

    double R = screenPosCenter.y - screenPosStart.y; 
    int N = 120;//N is the number of parts we are dividing the circle 
    double T = 2*Math.PI/N; 
    double theta = T; 

    screenPosEnd = new Point(); 
    screenPosEnd.x = (int)(screenPosCenter.x-R*Math.sin(theta)); 
    screenPosEnd.y = (int) (screenPosCenter.y-R*Math.cos(theta)); 
    end = p.fromScreenLocation(screenPosEnd); 

    for(int i =0;i<N;i++){ 
     theta+=T; 
     if(i%2 == 0){ 
      //dottedCircle is a hashmap to keep reference to all the polylines added to map 
      dottedCircle.add(mMap.addPolyline(new PolylineOptions().add(start,end).width(5).color(Color.BLACK))); 

      screenPosStart.x = (int) (screenPosCenter.x-R*Math.sin(theta)); 
      screenPosStart.y = (int) (screenPosCenter.y-R*Math.cos(theta)); 
      start = p.fromScreenLocation(screenPosStart); 
     } 
     else{ 
      screenPosEnd.x = (int)(screenPosCenter.x-R*Math.sin(theta)); 
      screenPosEnd.y = (int) (screenPosCenter.y-R*Math.cos(theta)); 
      end = p.fromScreenLocation(screenPosEnd); 
     } 

    } 

} 

Image after drawing the dotted circle

座標LatLngs