分享Android CellLocation源码,基于Rexsee对象的基站定位功能
来源:互联网 发布:淘宝异地客服 编辑:程序博客网 时间:2024/05/17 22:40
[代码] 代码段示例
01
function query(){
02
var loction = eval(
'('
+rexseeCellLocation.getLastKnownLocation()+
')'
);
03
var type = location.type.toLowerCase();
04
var mcc = parseInt(location.operator.substring(
0
,
3
));
05
var mnc = (type==
'gsm'
)?parseInt(location.operator.substring(
3
)):location.systemId;
06
var cid= (type==
'gsm'
)?location.cid:location.baseStationId;
07
var lac= (type==
'gsm'
)?location.lac:location.networkId;
08
var postData=
"{\version\":\"1.1.0\",\"host\":\maps.google.com\",\"access_token\";\"2:k7j3G6LaL6u_lafw:4iXOeOpTh1glSXe\",\"home_mobile_country_code\":"
+mcc+
",\"home_mobile_network_code\":"
+mnc+
",\"address_language\";\"zh_CN\",\"radio_type\";\""
+type+
"\",\"request_address\":true,\"cell_towers\":[{\"cell_id\":+cid+"
,\
"location_area_code\":+lac+"
,\
"mobile_aountry_code\":"
+mcc+
",\"mobile_network_code\":"
+mnc+
",\"timing_advance\":5555}]}"
;
09
10
alert(rexseeAjax.syncSubmit(
'http://www.google.com/loc/json'
,postData,
'utf-8'
));
11
}
[图片] 1318156045.jpg
[代码] RexseeCellLocation对象
001
/*
002
* Copyright (C) 2011 The Rexsee Open Source Project
003
*
004
* Licensed under the Rexsee License, Version 1.0 (the "License");
005
* you may not use this file except in compliance with the License.
006
* You may obtain a copy of the License at
007
*
008
* http://www.rexsee.com/CN/legal/license.html
009
*
010
* Unless required by applicable law or agreed to in writing, software
011
* distributed under the License is distributed on an "AS IS" BASIS,
012
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013
* See the License for the specific language governing permissions and
014
* limitations under the License.
015
*/
016
017
package
rexsee.location;
018
019
import
rexsee.core.browser.JavascriptInterface;
020
import
rexsee.core.browser.RexseeBrowser;
021
import
android.content.Context;
022
import
android.telephony.CellLocation;
023
import
android.telephony.PhoneStateListener;
024
import
android.telephony.TelephonyManager;
025
import
android.telephony.cdma.CdmaCellLocation;
026
import
android.telephony.gsm.GsmCellLocation;
027
028
public
class
RexseeCellLocation
implements
JavascriptInterface {
029
030
private
static
final
String INTERFACE_NAME =
"CellLocation"
;
031
@Override
032
public
String getInterfaceName() {
033
return
mBrowser.application.resources.prefix + INTERFACE_NAME;
034
}
035
@Override
036
public
JavascriptInterface getInheritInterface(RexseeBrowser childBrowser) {
037
return
this
;
038
}
039
@Override
040
public
JavascriptInterface getNewInterface(RexseeBrowser childBrowser) {
041
return
new
RexseeCellLocation(childBrowser);
042
}
043
044
public
static
final
String EVENT_ONCELLLOCATIONCHANGED =
"onCellLocationChanged"
;
045
046
public
final
Context mContext;
047
private
final
RexseeBrowser mBrowser;
048
private
final
int
mPhoneType;
049
private
PhoneStateListener mListener =
null
;
050
private
CellLocation mLocation =
null
;
051
052
public
RexseeCellLocation(RexseeBrowser browser) {
053
mContext = browser.getContext();
054
mBrowser = browser;
055
browser.eventList.add(EVENT_ONCELLLOCATIONCHANGED);
056
TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
057
mPhoneType = tm.getPhoneType();
058
}
059
060
//JavaScript Interface
061
public
boolean
isEnabled() {
062
return
mListener !=
null
;
063
}
064
public
boolean
enable() {
065
try
{
066
TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
067
mListener =
new
PhoneStateListener() {
068
@Override
069
public
void
onCellLocationChanged(CellLocation location) {
070
mLocation = location;
071
mBrowser.eventList.run(EVENT_ONCELLLOCATIONCHANGED);
072
}
073
};
074
tm.listen(mListener, PhoneStateListener.LISTEN_CELL_LOCATION);
075
return
true
;
076
}
catch
(Exception e) {
077
mBrowser.exception(getInterfaceName(), e);
078
return
false
;
079
}
080
}
081
public
boolean
disable() {
082
if
(mListener ==
null
)
return
true
;
083
try
{
084
TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
085
tm.listen(mListener, PhoneStateListener.LISTEN_NONE);
086
mListener =
null
;
087
return
true
;
088
}
catch
(Exception e) {
089
mBrowser.exception(getInterfaceName(), e);
090
return
false
;
091
}
092
}
093
public
String getLastKnownLocation() {
094
if
(mLocation ==
null
)
return
"{}"
;
095
TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
096
String rtn =
""
;
097
rtn +=
"\"operator\":\""
+ tm.getNetworkOperator() +
"\""
;
098
rtn +=
",\"operatorName\":\""
+ tm.getNetworkOperatorName() +
"\""
;
099
if
(mPhoneType == TelephonyManager.PHONE_TYPE_GSM) {
100
GsmCellLocation gsm = (GsmCellLocation) mLocation;
101
rtn +=
",\"type\":\"GSM\""
;
102
rtn +=
",\"cid\":"
+ gsm.getCid();
103
rtn +=
",\"lac\":"
+ gsm.getLac();
104
}
else
if
(mPhoneType == TelephonyManager.PHONE_TYPE_CDMA) {
105
CdmaCellLocation cdma = (CdmaCellLocation) mLocation;
106
rtn +=
",\"type\":\"CDMA\""
;
107
rtn +=
",\"baseStationId\":"
+ cdma.getBaseStationId();
108
rtn +=
",\"baseStationLatitude\":"
+ cdma.getBaseStationLatitude();
109
rtn +=
",\"baseStationLongitude\":"
+ cdma.getBaseStationLongitude();
110
rtn +=
",\"networkId\":"
+ cdma.getNetworkId();
111
rtn +=
",\"systemId\":"
+ cdma.getSystemId();
112
}
113
return
"{"
+ rtn +
"}"
;
114
}
115
116
}
- 分享Android CellLocation源码,基于Rexsee对象的基站定位功能
- 分享Android CellLocation源码,基于Rexsee对象的基站定位功能
- 分享Android CellLocation源码,基于Rexsee对象的基站定位功能
- Rexsee API介绍:基站定位功能,Android CellLocation源码
- 基站定位-基于基站的移动台定位系统
- 基站定位-基于基站的移动台定位
- Android的基站、WIFI、GPS定位集合【源码】
- Android的基站定位实现
- 基于基站的移动台定位
- 基于基站和GPS的LBS定位
- 基于基站的移动台定位
- 基于基站和小区的定位技术研究
- Rexsee API介绍:Android视频播放,Rexsee的VideoPlayer函数说明与源码
- android定位之基站的定位(含GSM与cdma实现源码)
- 基站定位示例源码
- Rexsee是基于Android的HTML5开发平台
- android GPS定位,基站定位,WIFI定位开关的控制
- 真实可行的android 基站定位代码
- mysql重装的问题
- 身份验证session cookies
- view设置成圆角
- 分享Android CellLocation源码,基于Rexsee对象的基站定位功能
- 为什么我的程序编译后生成很多*$1.class文件?
- 分享Android CellLocation源码,基于Rexsee对象的基站定位功能
- 用gSOAP访问WebService,QVOD搜索神器命令行版 (摘)
- 用户信息修改验证输入
- "CWinApp::Enable3dControls”引起的C4996告警
- Linux JDK 环境设置
- 设计模式大集锦 程序员面试全攻略
- SQL语句oracle中如何插入Date类型的数据
- const 与 readonly知多少
- 配置rsh无密码访问