2016-11-14 5 views
-1

지도를 사용하여 사용자 위치를 파악할 수있는 다른 방법이 있는지 물어보고 싶습니다. 일부 쿼리를 수행 할 위치 만 원합니다. 거기에 있습니다. 안드로이드에서지도 활동을 포함하여 이것을 수행하는 더 현명하고 효율적인 방법은 무엇입니까?지도를 사용하여 사용자 (위도, 경도) 위치를 벗어나지 마십시오. Android

+3

을 당신 : https://developer.android.com/training/location/index.html – c0rtexx

답변

1

Android는 사용자의 위치를 ​​결정하는 두 가지 기본 방법이 있습니다. 첫 번째는 Android가 처음 소개 된 이후부터 사용할 수 있었던 기본 제공 위치 API를 사용하는 것입니다. Google Play 서비스가 있습니다.

그래서 당신은지도를 사용하지 않고 말한대로 :

LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
    Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
    double longitude = location.getLongitude(); 
    double latitude = location.getLatitude(); 

final LocationListener locationListener = new LocationListener() { 
     public void onLocationChanged(Location location) { 
      longitude = location.getLongitude(); 
      latitude = location.getLatitude(); 
     } 

     public void onProviderDisabled(String arg0) { 
      // TODO Auto-generated method stub 

     } 

     public void onProviderEnabled(String arg0) { 
      // TODO Auto-generated method stub 

     } 

     public void onStatusChanged(String arg0, int arg1, Bundle arg2) { 
      // TODO Auto-generated method stub 

     } 
    }; 
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 10, locationListener); 

당신이 GPS 사용하려면 허가를 잊지 마세요 :

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

확인 이상이 문서 : 여기 https://developer.android.com/guide/topics/location/strategies.html