2016-09-08 5 views
0

Google지도를 사용하여 점선으로 된 폴리선을 그릴 수있는 기능이 iOS에 내장되어 있지만 Android 용으로 해당 기능을 찾을 수 없습니다. 아이디어는 iOS가 두 가지 색상을 설정할 수 있다는 것입니다. 하나는 선의 색상이고 다른 하나는 (투명) 사이의 공간이므로 점선이 생성됩니다. iOS 구현은 다음과 같습니다.Google지도를 사용하여 점선으로 된 폴리선 그리기 - Android

- (GMSPolyline)drawDashPath:(GMSPath) path{ 
    GMSPolyline *polyline = [GMSPolyline polylineWithPath:path]; 
    polyline.map = self.googleMapView; 
    polyline.strokeWidth = 5.0; 
    NSArray *styles = @[[GMSStrokeStyle solidColor:[UIColor blueColor]],[GMSStrokeStyle solidColor:[UIColor clearColor]]]; 
    NSArray *lengths = @[@5, @5]; 
    polyline.spans = GMSStyleSpans(polyline.path, styles, lengths, kGMSLengthRhumb); 
    return polyline; 
} 

Android의 경우 점선을 얻었지만 계산 및 조작을 통해 수행해야했습니다. 여기에 내가 안드로이드

   // calculate the difference in latitude and longitude between start and end points 
       double difLat = latLngDest.latitude - latLngOrig.latitude; 
       double difLng = latLngDest.longitude - latLngOrig.longitude; 

       // retrieve current zoom level 
       double zoom = mMap.getCameraPosition().zoom; 

       // come up with distance between dotted lines that adjusts according to zoom levels 
       double divLat = difLat/(zoom * 1.2); 
       double divLng = difLng/(zoom * 1.2); 
       LatLng tmpLatOri = latLngOrig; 

       // add polyline to list 
       for (int i = 0; i < (zoom * 1.2); i++) { 
        LatLng loopLatLng = tmpLatOri; 

        if (i > 0) { 
         loopLatLng = new LatLng(tmpLatOri.latitude + (divLat * 0.40f), tmpLatOri.longitude + (divLng * 0.40f)); 
        } 

        polylineList.add(mMap.addPolyline(new PolylineOptions() 
            .add(loopLatLng) 
            .add(new LatLng(tmpLatOri.latitude + divLat, tmpLatOri.longitude + divLng)) 
            .color(Utils.getColor(mContext, R.color.orange)) 
            .width(18f))); 
        tmpLatOri = new LatLng(tmpLatOri.latitude + divLat, tmpLatOri.longitude + divLng); 
       } 

이 확인 보이는을 위해 일을하고있다,하지만 난 오히려이 존재하는 경우이 기능 내장 사용하는 것입니다. 설명서를 살펴본 결과 Android를 찾을 수 없습니다.

답변

2

2017 년 2 월 Google은 Google Maps Android API v2에서 폴리 라인 및 폴리곤에 대한 새로운 맞춤 설정을 발표했습니다. 특히 파선 및 점선으로 된 폴리선을 만들 수 있습니다.

Shapes Guide의 새로운 기능에 대한 정보를 참조하십시오. 폴리 라인 및 폴리곤 자습서의 example을 참조하십시오.

또한 여기에 해당 블로그 게시물을 읽을 수 있습니다

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

+0

에서 [복수의 질문에 같은 대답]을 추가하지 마십시오 (http://meta.stackexchange.com/questions/104227/를 광고에 적합합니까? 여러 번에 걸쳐 여러 번 질문에 답변 할 수 있습니다 (세 번 째). 가장 좋은 답변을하고 나머지는 평판이 좋으면 중복으로 표시하십시오. 중복이 아닌 경우 질문에 대한 게시물을 맞춤 설정하십시오. –

1

아직 Android에는 존재하지 않습니다.

관련 문제