2015-02-03 4 views
0

내 프로젝트에 Google지도가 있습니다. 확대/축소 수준 18로 설정되었습니다. 길이가 1 미터 인 선을 그립니다. 나는 코드를보고 사용했다. 이것처럼 :Android Google지도 V2 : 특정 길이의 선을 그리려면 어떻게해야하나요?

googleMap.addCircle(new CircleOptions() 
    .center(latLng1) 
    .radius(5) 
    .fillColor(Color.BLUE));  

나는 그것의 반지름을 미터로했다. 선으로 어떻게 할 수 있습니까? (polyLine에는이 옵션이 없습니다) 특정 LatLng 및 특정 방향이있는 선 (예 : 북쪽에서 표제)과 특정 길이? 죄와 코 코스로 방향을 지정할 수는 있지만 길이가 길면 무엇을 할 수 있습니까?

답변

2

, 아래와 같은 라인 뭔가를 그립니다. 그러나 라인과 상황은 조금 다릅니다. 주어진 점에 대해이 점과 주어진 길이에서 시작하는 무한 수의 선이 있습니다. 그러므로 그와 같은 선을 그릴 수는 없습니다.

하나의 방법은 반경 1 미터의 원 위에 점을 찍고 점을 중심에 배치하는 것입니다. Here은 주어진 반지름으로 원의 점을 계산하는 좋은 예입니다. 두 점 사이에 선을 그리는 것보다.

UPDATE :

이 방법 원에 LatLng를 포인트를 찾을 수있는 도움이 될 수 LatLng Points on circle on Google Map V2 in Android

+0

방향을 지정하면 ... 그릴 선이 하나뿐입니다. 한 점, 길이 및 방향 (도) ... 나는 제안 페이지를 시도 할 것입니다 – jion

+0

문제는 : 어떻게 1 미터를 지정할 수 있습니까? 예 : LatLng2.longitude = r x cos (a); 및 LatLng2.latitude = r × sin (a); 하지만 "r"이 1 미터라고 Google지도에 어떻게 설명 할 수 있습니까? – jion

+0

많이 고마워요. 사용했지만 문제가 있습니다. 여기에서 설명했습니다. http://stackoverflow.com/questions/28321738/android-google-map-heading-is-drawn-wrongly-when-i-draw-a-line-with-specific – jion

0

사용 폴리 라인은 주어진 반경 하나의 원이 특정 시점에 대한

private ArrayList<LatLng> mLatlngs ; 

PolylineOptions mPolylineOptions = new PolylineOptions(); 
        mPolylineOptions.color(Color.RED); 
        mPolylineOptions.width(3); 
        mPolylineOptions.addAll(mLatlngs); 
        mGoogleMap.addPolyline(mPolylineOptions); 
+0

나는 나의 ne를 모른다. xt point의 LatLng ... 나는 단지 특별한 너비의 선을 그립니다. – jion

1

내가 사용하는 라인의 끝을 계산하려면

SphericalUtil.computeOffset(LatLng,lenght,heading); 

미터에 폭을 계산하기 I 이것을 사용하십시오 :

public Double calcw(GoogleMap map,int ancho,LatLng p) { 
    float tilt = map.getCameraPosition().tilt; 
    CameraPosition old=map.getCameraPosition(); 
    if(tilt!=0){ 
     CameraPosition cameraPosition = new CameraPosition.Builder() 
       .target(old.target)  // Sets the center of the map to Mountain View 
       .zoom(old.zoom)     // Sets the zoom 
       .bearing(old.bearing)    // Sets the orientation of the camera to east 
       .tilt(0)     // Sets the tilt of the camera to 30 degrees 
       .build(); 
     map.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); 

    } 
    Point g1 =map.getProjection().toScreenLocation(p); 
    Point g2=map.getProjection().toScreenLocation(SphericalUtil.computeOffset(p,ancho/10,0)); 

    Double result=(distance(g1,g2)); 
    //Log.e("PROJ1",Double.toString(distance(g1,g2))); 

    map.moveCamera(CameraUpdateFactory.newCameraPosition(old)); 
    return result; 

     } 
    public double distance(Point a, Point b) 
{ 
    double dx = a.x - b.x; 
    double dy = a.y - b.y; 
    return Math.sqrt(dx * dx + dy * dy); 
} 
관련 문제