2014-10-10 2 views
1

Google지도가있는 안드로이드 응용 프로그램이 있습니다. 사용자가 현재 방향을 따라 걷는 방법을 누가 알 수 있습니까? 나는 많은 정보를 읽었지만 아직도 혼란 스럽다.현재 진행 방향에 따라지도 회전 안드로이드 Google지도

감사

+0

오리엔테이션 센서를 조사하고 싶을 수도 있습니다. – zgc7009

+0

가능한 중복 [this] (http://stackoverflow.com/questions/14767282/android-maps-v2-rotate-mapview-with-compass) 및 [this] (http://stackoverflow.com/questions/1830391/ rotate-mapview-in-android) – Antrromet

답변

1

당신은 두 점을 비교하여 베어링을 계산할 수 있습니다. 당신은 당신의 사용자가 걷기 때문에 너무 멀리 떨어져서 두 점을 서로 떨어 뜨려서는 안된다고 말했습니다.

당신이 두 점을

이러한 우리의 변환 함수 그래서

lon1 = degToRad(lon1); 
lon2 = degToRad(lon2); 
lat1 = degToRad(lat1); 
lat2 = degToRad(lat2); 

double a = Math.Sin(lon2 - lon1) * Math.Cos(lat2); 
double b = Math.Cos(lat1) * Math.Sin(lat2) - Math.Sin(lat1) * Math.Cos(lat2) * Math.Cos(lon2 - lon1); 
double c = radToDeg(Math.Atan2(a, b)); // c is our bearing // 

같은 몇 가지 수학을

public static double degToRad(double deg){ 
    return deg * Math.PI/180.0; 
} 
public static double radToDeg(double rad){ 
    rad = rad * (180.0/Math.PI); 
    if (rad < 0) rad = 360.0 + rad; 
    return rad; 
} 

일단 당신이 당신이 CameraUpdateFactory를 사용하여지도에 전달할 수 베어링.

map.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(LatLng, zoom, tilt, bearing))); 
+0

함수는 다음과 같습니다 : 'float targetBearing = currentLocation.bearingTo (endingLocation)'? – pdcc

+0

그것은 나를 위해 일했습니다 감사합니다. – Kokusho