SORU
9 ŞUBAT 2010, Salı


Nasıl android mobil cihaz Enlem ve Boylam?

Nasıl android mobil cihazın konumunu araçları kullanarak geçerli Enlem ve Boylam alabilirim?

CEVAP
9 ŞUBAT 2010, Salı


LocationManager kullanın.

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

Çağrı getLastKnownLocation() gelmiyor blok - yani geri dönecektir null eğer hiçbir konumu mevcut - bu yüzden muhtemelen bir bak geçer LocationListener requestLocationUpdates() method bunun yerine, size zaman uyumsuz güncelleştirmeleri konumunuzu.

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

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

Eğer GPS kullanmak isterseniz uygulamanızın ACCESS_FINE_LOCATION permission vermek gerekir.

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

Ayrıca GPS olmadığında ACCESS_COARSE_LOCATION permission Ekle getBestProvider() method ile konum sağlayıcı seçmek isteyebilirsiniz.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • AutoHotkey Tutorials

    AutoHotkey T

    29 Mayıs 2010
  • PremiumBeat.com - Royalty Free Music

    PremiumBeat.

    16 Kasım 2008
  • Tracy Hairston

    Tracy Hairst

    22 Mayıs 2009