任何人都可以给我一个代码,获取black berry 8520 os 5.0版的cellsite gps位置。 我的手机详情:
model:bb curve 8520
version :5.0.0.1036
carrier:airtel (post paid )
location :Andhra Pradesh ,India
data services :on
当我安装谷歌地图时,我能够看到该位置,因此有可能使用这款手机获取当前位置。
我正在尝试开发一个应用程序,通过使用手机站点位置来显示手机的当前位置,因为这款手机型号没有内置GPS设备。
请紧急 我在互联网上尝试了几个例子但是徒劳无功。提前致谢
这是我用过的代码:
BlackBerryCriteria bc=new BlackBerryCriteria(GPSInfo. GPS_MODE_CELLSITE );
try {
LocationProvider lp=LocationProvider.getInstance(bc);
if(lp !=null)
{
Location loc=lp.getLocation(-1);
add (new EditField(loc.getQualifiedCoordinates().getLatitude()+"\n"+loc.getQualifiedCoordinates().getLongitude(),""));
}
else
{
add(new EditField("unable to find the location provider", ""));
}
} catch (LocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}
但是我想要一个未被捕获的例外 net.rim.device.api.UnsupportedOperationException。
请紧急帮助
答案 0 :(得分:0)
答案 1 :(得分:0)
import java.util.TimerTask;
import javax.microedition.location.Criteria;
import javax.microedition.location.Location;
import javax.microedition.location.LocationException;
import javax.microedition.location.LocationListener;
import javax.microedition.location.LocationProvider;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
public class HandleMAPAPI
{
static boolean _isCancel = false;
private Criteria criteria;
double latitude ,longitude;
TimerTask _loadinglatlon;
private LocationProvider provider,_locationProvider;
Location location = null;
boolean _islatlong;
public HandleMAPAPI()
{
startLocationUpdate() ;
}
public void startLocationUpdate()
{
try{
_locationProvider = LocationProvider.getInstance(null);
if (_locationProvider != null) {
_locationProvider.setLocationListener(
new LocationListenerImpl(), 1, 1, 1);
} else {
setupCriteria();
setupProvider();
}
}catch(LocationException le){
System.out.println("----Exception Of Location--"+le);
}
}
/**
* Initializes criteria according to the mode selected by the user.
*/
private void setupCriteria() {
criteria = new Criteria();
criteria.setCostAllowed(true);
criteria.setHorizontalAccuracy(Criteria.NO_REQUIREMENT);
criteria.setVerticalAccuracy(Criteria.NO_REQUIREMENT);
criteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW);
}
/**
* Initializes LocationProvider based on specified mode and Criteria.
*/
private void setupProvider() {
try {
// Just to give setupPDE and criteria setup.. some time. This may
// not be needed at all.
try {
Thread.sleep(5000);
} catch (Throwable e) {
System.out.println(e.toString());
}
provider = LocationProvider.getInstance(criteria);
if (provider != null) {
singleFixLocationUpdate();
} else {
//Utilites.log("Provider unavailable for that Criteria");
}
} catch (Throwable t) {
System.out.println(t.toString());
}
}
/**
* Gets a single fix by calling LocationProvider.getLocation().
*/
private void singleFixLocationUpdate() {
try {
location = provider.getLocation(-1);
} catch (InterruptedException ie) {
System.out.println("InterruptedException thrown by getLocation(): "
+ ie.toString());
} catch (LocationException le) {
System.out.println("LocationException thrown by getLocation(): "
+ le.toString());
} catch (Throwable t) {
System.out.println(t.toString());
}
if (location != null) {
if (location.isValid()) {
System.out.println("Valid single fix: "
+ location.getQualifiedCoordinates().getLatitude()
+ ", "
+ location.getQualifiedCoordinates().getLongitude()
+ " "
+ location.getQualifiedCoordinates().getAltitude());
longitude= location.getQualifiedCoordinates()
.getLongitude();
latitude = location.getQualifiedCoordinates()
.getLatitude();
if (longitude != 0.0 && latitude != 0.0) {
}
else{
System.out.println("----Cell site Sunnyvale--");
}
} else {
System.out.println("Invalid single fix");
}
} else
{
closeLoading("null", "null");
Dialog.alert("No GPS Found");
}
}
public class LocationListenerImpl implements LocationListener {
public void locationUpdated(LocationProvider provider, Location location) {
System.out.println("---Location Updated-----");
if (location.isValid()) {
System.out.println("---Location Valid----");
longitude = location.getQualifiedCoordinates()
.getLongitude();
latitude= location.getQualifiedCoordinates()
.getLatitude();
if (longitude != 0.0 && latitude != 0.0) {
} else {
System.out.println("--Cellsite valide=-----");
setupCriteria();
setupProvider();
}
_locationProvider.setLocationListener(null, 0, 0, 0);
}else{
System.out.println("else NOT valid--Cellsite valide=-----");
setupCriteria();
setupProvider();
}
System.out.println("---Location Not Valid----");
}
public void providerStateChanged(LocationProvider provider, int newState) {}
}
}