更新2:問題解決的Galaxy Tab - 應用程序中獲得的網絡或被動提供商沒有GPS定位
我在外面,並獲得與GPS_PROVIDER的信號後,現在我已經不是一個問題了獲得位置鎖定與NETWORK_PROVIDER ....
我仍然不知道爲什麼谷歌地圖的應用程序能夠得到修復之前,我這樣做,我的應用程序沒有,但現在它的作品(即使重新啓動星系標籤),我很高興;)
UPDATE:thread title chang請參閱帖子底部的修改。
我只是嘗試本教程(http://www.firstdroid.com/2010/04/29/android-development-using-gps-to-get-current-location-2/)的星系選項卡上得到一個GPS的位置,但我沒有得到任何地點....
我已經嘗試過使用其他供應商但這並不幫助(我嘗試了GPS_PROVIDER,NETWORK_PROVIDER,PASSIVE_PROVIDER)。
奇怪的是,與官方谷歌地圖應用程序我得到一個位置。 :\
在AndroidManifest.xml的權限設置如下:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
有誰知道爲什麼我的應用程序中獲得的任何位置?
編輯:
與GPS供應商,我得到修復,當我是外地人。但我不明白爲什麼我沒有NETWORK_PROVIDER或PASSIVE_PROVIDER的位置。
如果GPS不可用,哪個提供者執行google地圖應用使用?
編輯2:
代碼(這是從上面的教程進行一些小改動):
package Firstdroid.Tutorial.Gps;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;
public class UseGps extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Toast.makeText(getApplicationContext(), "Application started", Toast.LENGTH_SHORT).show();
/* Use the LocationManager class to obtain GPS locations */
LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
// here I choose the location provider:
mlocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, mlocListener); // <---
}
/* Class My Location Listener */
public class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location loc) {
loc.getLatitude();
loc.getLongitude();
String Text = "My current location is: " +
"Latitude = " + loc.getLatitude() +
"Longitude = " + loc.getLongitude() + " (PROVIDER: " + loc.getProvider() + ")";
Toast.makeText(getApplicationContext(), Text, Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderDisabled(String provider) {
Toast.makeText(getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderEnabled(String provider) {
Toast.makeText(getApplicationContext(),
"Gps Enabled", Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}/* End of Class MyLocationListener */
}/* End of UseGps Activity */
你可以發佈你的代碼設置你的locationlistener等。?另外,如果你要求罰款,你不需要粗魯的要求;罰款處理網絡和GPS提供商。 – Kevin 2012-03-29 14:17:28
你好,我剛剛看到你的評論。所以GPS_PROVIDER的作品,但我不明白,NETWORK_PROVIDER或PASSIVE_PROVIDER不起作用。 哦,我會在第一篇文章中添加代碼。 – LittleJohn 2012-03-29 14:35:17