如何在Blackberry OS 5上获得无GPS的地理定位
我已经从操作系统5和更高版本的GPS获得了地理位置信息 我需要从网络上获取地理位置信息。如果GPS被禁用,我需要从OS5的网络中收集地理位置信息 我查过了 他们为OS6和更高版本提供了解决方案 我们可以在没有GPS的情况下为blackberry OS 5获取地理位置信息吗?试试这个-如何在Blackberry OS 5上获得无GPS的地理定位,blackberry,java-me,gps,Blackberry,Java Me,Gps,我已经从操作系统5和更高版本的GPS获得了地理位置信息 我需要从网络上获取地理位置信息。如果GPS被禁用,我需要从OS5的网络中收集地理位置信息 我查过了 他们为OS6和更高版本提供了解决方案 我们可以在没有GPS的情况下为blackberry OS 5获取地理位置信息吗?试试这个- try { int cellID = GPRSInfo.getCellInfo().getCellId(); int lac = GPRSInfo.getCellInfo().getLAC();
try {
int cellID = GPRSInfo.getCellInfo().getCellId();
int lac = GPRSInfo.getCellInfo().getLAC();
String urlString2 = "http://www.google.com/glm/mmap";
if ((WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)
&& RadioInfo
.areWAFsSupported(RadioInfo.WAF_WLAN)) {
urlString2 += ";interface=wifi;ConnectionTimeout=60000";
}else if (TransportInfo.isTransportTypeAvailable(TransportInfo.TRANSPORT_BIS_B) && TransportInfo.hasSufficientCoverage(TransportInfo.TRANSPORT_BIS_B)) {
System.out.println("BIS CONNECTION-------------------");
// Holder.connectionInterface=";deviceside=false;ConnectionType=mds-public";
urlString2 += ";deviceside=false;ConnectionType=mds-public;ConnectionTimeout=60000";
}
// Open a connection to Google Maps API
ConnectionFactory connFact = new ConnectionFactory();
ConnectionDescriptor connDesc;
connDesc = connFact.getConnection(urlString2);
HttpConnection httpConn2;
httpConn2 = (HttpConnection)connDesc.getConnection();
httpConn2.setRequestMethod("POST");
// Write some custom data to Google Maps API
OutputStream outputStream2 = httpConn2.openOutputStream();//getOutputStream();
WriteDataGoogleMaps(outputStream2, cellID, lac);
// Get the response
InputStream inputStream2 = httpConn2.openInputStream();//getInputStream();
DataInputStream dataInputStream2 = new DataInputStream(inputStream2);
// Interpret the response obtained
dataInputStream2.readShort();
dataInputStream2.readByte();
int code = dataInputStream2.readInt();
//Dialog.alert(code+"");
if (code == 0) {
latitude= dataInputStream2.readInt() / 1000000D;
longitude=dataInputStream2.readInt() / 1000000D;
//Dialog.alert(latitude+"-----"+longitude);
dataInputStream2.readInt();
dataInputStream2.readInt();
dataInputStream2.readUTF();
} else {
System.out.println("Error obtaining Cell Id ");
}
outputStream2.close();
inputStream2.close();
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
WriteDataTagoogleMaps()方法-
private static void WriteDataGoogleMaps(OutputStream out, int cellID, int lac)
throws IOException {
DataOutputStream dataOutputStream = new DataOutputStream(out);
dataOutputStream.writeShort(21);
dataOutputStream.writeLong(0);
dataOutputStream.writeUTF("en");
dataOutputStream.writeUTF("Android");
dataOutputStream.writeUTF("1.0");
dataOutputStream.writeUTF("Web");
dataOutputStream.writeByte(27);
dataOutputStream.writeInt(0);
dataOutputStream.writeInt(0);
dataOutputStream.writeInt(3);
dataOutputStream.writeUTF("");
dataOutputStream.writeInt(cellID);
dataOutputStream.writeInt(lac);
dataOutputStream.writeInt(0);
dataOutputStream.writeInt(0);
dataOutputStream.writeInt(0);
dataOutputStream.writeInt(0);
dataOutputStream.flush();
}
此外,您的另一个选择是使用,它适用于OS 5.0及更高版本 并将其包含在您的项目中 然后,要在不使用GPS的情况下获取定位,请尝试以下操作:
试试看{
simpleProvider=新的SimpleLocationProvider(SimpleLocationProvider.MODE\u地理位置);
}捕获(位置异常){
//如果所选模式(在本例中为模式\地理位置)不可用,则引发。
}
BlackBerryLocation location=simpleProvider.getLocation(120);//120秒超时
如果希望在指定的时间间隔使用位置数据回调代码,也可以使用该接口
在OS 6.0中,此API增加了专门选择蜂窝网络作为位置提供商或使用Wi-Fi网络的功能。在OS 5.0中,您仅限于以下三种选择:
模式\u地理定位-严格按照地理定位模式操作GPS模式- 严格在GPS(又名独立/自主)模式下运行
模式\u最优-基于 可用性
但是,使用
MODE\u GEOLOCATION
或MODE\u OPTIMAL
将允许您在不使用GPS芯片的情况下获得定位信息。hi。。在WriteDataGoogleMaps()方法中我们做什么?嗨,signare,它只在wifi网络上工作?我已检查关闭wifi,并连接3g sim卡。这不是地理点。。我该换什么?换连接字符串,然后try@Ganesh,我建议将上面使用连接字符串的代码替换为使用OS 5.0中添加的ConnectionFactory
API的代码。它使您可以更轻松地选择多个网络传输,以便连接到http://www.google.com/glm/mmap
URL.@Signare hi.,我已连接wifi,并插入3g sim卡。它的工作是从sim卡获取位置。如果我禁用移动网络。此代码不起作用。我们可以通过无线网络获取位置吗?嗨。我已经在我的设备9550上加载了cod文件。当我们选择“GEOLOATION”时,它会抛出一个异常。javax.microedition.locaion.LocaionEception:MODE_GEOLOCATION当前在此设备上不可用。@Ganesh,您尝试此操作时是否有移动互联网覆盖(网络可用)?需要明确的是,此模式使用GPSInfo.GPS\u mode\u CELLSITE
,它使用GSM或CDMA蜂窝网络。如果您的测试设备只有Wi-Fi连接,但没有有效的运营商网络,那么它将不适用于您。看看你对另一个答案的评论,你似乎在寻找一种不用Wi-Fi就能获得位置的方法。对于定位服务,特别是在OS5.0上,它通常需要多种技术的结合,这就是为什么我在Signare的答案之外添加了第二个答案。我的手机可以上网。我已插入3g sim卡,并且还可以使用wifi。@Ganesh,在这种情况下,Wi-Fi对您没有帮助。插入3G SIM卡很好,但也必须配置移动网络。如果关闭Wi-Fi,您能否通过3G正常访问互联网?而且,有可能是你的运营商阻止了这一点。你用的是哪家航空公司?您是否与该运营商签订了普通的黑莓计划,或者您是否与其他移动设备(例如,作为您主要手机的Android设备)共享此SIM卡?我已关闭wifi连接。我查过3g网络。我已经打开浏览器,检查网络是否可用。3g网络正在工作。我不知道它是bis连接。我想这是正常的3g网络连接。我已将sim卡换成android手机,并检查网络连接。它也在安卓手机上工作。。