2012-05-25 56 views
-1

我使用Telnet獲取了模擬器中的緯度和經度值(即GPS)。使用gps獲取經緯度的當前位置

我有一個疑問(即)沒有谷歌地圖,我們可以使用經度和緯度得到當前位置。

+1

@BB專家:這是完全錯誤的。在瞭解當前的緯度和經度並能夠在地圖上顯示它之間沒有任何關係。 – NickT

+0

@BB專家:我們可以使用locationManager獲取位置,而無需使用谷歌地圖。 –

+1

這種問題問了很多次,你應該在發佈問題之前進行搜索。 @cholocateboy – Lucifer

回答

0

您可以使用GPS和Google地圖同時獲取當前位置。如果你想通過谷歌地圖獲取位置,然後plz show this教程。你可以see this先前提問的問題。

如果你想獲取沒有谷歌地圖的位置,那麼你可以使用位置管理器。

要做到這一點,我們需要在OnCreate方法中添加代碼休耕:

/* Use the LocationManager class to obtain GPS locations */ 
LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
LocationListener mlocListener = new MyLocationListener(); 
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener); 

在自定義類MyLocationListener使用實現接口LocationListener的。

我們將添加我們自己的個人Location監聽器,因此我們可以覆蓋一些功能來執行我們想要的功能。在我們的例子中,我們只是打印一條消息到屏幕在撂荒情況:

onLocationChanged (Location Update) 
onProviderDisabled (GPS Off) 
onProviderEnabled (GPS On) 

並添加其他強制方法,它不會做任何事情。

onStatusChanged (We are not adding nothing here). 

之後給你許可在AndroidManifest.xml文件:

0

你可以通過這個代碼得到緯度和經度

GPS_Location mGPS = new GPS_Location(MyApplication.getAppContext()); 

if (mGPS.canGetLocation) { 

    mLat = mGPS.getLatitude(); 
    mLong = mGPS.getLongitude(); 

} else { 
    System.out.println("cannot find"); 
} 

必須添加GPS權限和其他權限到您的應用程序

相關問題