1
在我的應用程序中,我嘗試獲取用戶位置,但經緯度都是0.0。我已經看到黑莓論壇,但無法找到我做錯了什麼?獲取gps在黑莓的位置
代碼:
package com.MyChamberApp;
import javax.microedition.location.Criteria;
import javax.microedition.location.Location;
import javax.microedition.location.LocationListener;
import javax.microedition.location.LocationProvider;
public class GPS_Location {
static double longi;
static double lati;
public GPS_Location() {
}
public void location()
{
new LocationTracker();
}
class LocationTracker
{
private LocationProvider provider;
Criteria cr;
public LocationTracker()
{
resetGPS();
}
public void resetGPS() {
try {
cr = new Criteria();
cr.setPreferredPowerConsumption(Criteria.POWER_USAGE_HIGH);
cr.setPreferredResponseTime(120000);
cr.setCostAllowed(true);
provider = LocationProvider.getInstance(cr);
provider.getLocation(120);
if (provider != null)
{
provider.setLocationListener(new MyLocationListener(), 1,1,1);
}
} catch (Exception e) {}
}
public void run(){}
private class MyLocationListener implements LocationListener
{
public void providerStateChanged(LocationProvider provider,int newState)
{
if (newState == LocationProvider.TEMPORARILY_UNAVAILABLE)
{
provider.reset();
resetGPS();
}
if (newState == LocationProvider.OUT_OF_SERVICE)
{
provider.reset();
resetGPS();
}
}
public void locationUpdated(LocationProvider provider,Location location)
{
if (location != null && location.isValid()) {
try {
lati = location.getQualifiedCoordinates().getLatitude();
longi = location.getQualifiedCoordinates().getLongitude();
} catch (Exception e) {}
}
}
}
}
}
我已經嘗試了curve8300這個代碼,bold9000 它運作良好,在模擬器,但是,設備不取值,即使我手動刷新我的GPS,從選項 - >高級選項 - - > GPS。 在此先感謝!!!!!!!!!!!!!!!!
嘿,我認識一樣東西它不是給我的位置,完美的精度 做什麼 – Swati 2010-05-19 06:03:48
驗證碼需要很長時間才能獲取gps位置 – Swati 2010-05-19 07:52:51