- 浏览: 2180633 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (1240)
- mac/IOS (287)
- flutter (1)
- J2EE (115)
- android基础知识 (582)
- android中级知识 (55)
- android组件(Widget)开发 (18)
- android 错误 (21)
- javascript (18)
- linux (70)
- 树莓派 (18)
- gwt/gxt (1)
- 工具(IDE)/包(jar) (18)
- web前端 (17)
- java 算法 (8)
- 其它 (5)
- chrome (7)
- 数据库 (8)
- 经济/金融 (0)
- english (2)
- HTML5 (7)
- 网络安全 (14)
- 设计欣赏/设计窗 (8)
- 汇编/C (8)
- 工具类 (4)
- 游戏 (5)
- 开发频道 (5)
- Android OpenGL (1)
- 科学 (4)
- 运维 (0)
- 好东西 (6)
- 美食 (1)
最新评论
-
liangzai_cool:
请教一下,文中,shell、C、Python三种方式控制led ...
树莓派 - MAX7219 -
jiazimo:
...
Kafka源码分析-序列5 -Producer -RecordAccumulator队列分析 -
hp321:
Windows该命令是不是需要安装什么软件才可以?我试过不行( ...
ImageIO读jpg的时候出现javax.imageio.IIOException: Unsupported Image Type -
hp321:
Chenzh_758 写道其实直接用一下代码就可以解决了:JP ...
ImageIO读jpg的时候出现javax.imageio.IIOException: Unsupported Image Type -
huanghonhpeng:
大哥你真强什么都会,研究研究。。。。小弟在这里学到了很多知识。 ...
android 浏览器
基站定位程序
- 博客分类:
- android基础知识
贴代码
LauncherActivity.java
package com.android.demo; import java.util.Timer; import java.util.TimerTask; import android.app.Activity; import android.content.Intent; import android.os.Bundle; public class LauncherActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.launcher); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { // TODO Auto-generated method stub Intent goIntent = new Intent(); goIntent.setClass(LauncherActivity.this, DemoActivity.class); startActivity(goIntent); } }, 3*1000); } }
DemoActivity.java
package com.android.demo; import java.io.BufferedReader; import java.io.InputStreamReader; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.json.JSONArray; import org.json.JSONObject; import android.app.Activity; import android.app.ProgressDialog; import android.content.Context; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.telephony.TelephonyManager; import android.telephony.gsm.GsmCellLocation; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import android.view.View.OnClickListener; public class DemoActivity extends Activity { private MyHandler myHandler; private SCell cell; private ProgressDialog mProgressDialog; /** 根据基站数据获取经纬度 */ private SItude itude; /** 获取地理位置 */ private String location; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); /** 为按钮绑定事件 */ Button btnGetLocation = (Button) findViewById(R.id.button1); btnGetLocation.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub onBtnClick(); } }); } /** 基站信息结构体 */ public class SCell{ public int MCC; public int MNC; public int LAC; public int CID; } /** 经纬度信息结构体 */ public class SItude{ public String latitude; public String longitude; } /** 按钮点击回调函数 */ private void onBtnClick() { /** 弹出一个等待状态的框 */ myHandler=new MyHandler(); Toast.makeText(getApplicationContext(), "Ha", Toast.LENGTH_SHORT).show(); mProgressDialog = new ProgressDialog(this); mProgressDialog.setMessage("正在获取中..."); mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); mProgressDialog.show(); MyThread m = new MyThread(); new Thread(m).start(); } /** * 获取基站信息 * * @throws Exception */ private SCell getCellInfo() throws Exception { SCell cell = new SCell(); /** 调用API获取基站信息 */ TelephonyManager mTelNet = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); GsmCellLocation location = (GsmCellLocation) mTelNet.getCellLocation(); if (location == null) throw new Exception("获取基站信息失败"); String operator = mTelNet.getNetworkOperator(); int mcc = Integer.parseInt(operator.substring(0, 3)); int mnc = Integer.parseInt(operator.substring(3)); int cid = location.getCid(); int lac = location.getLac(); /** 将获得的数据放到结构体中 */ cell.MCC = mcc; cell.MNC = mnc; cell.LAC = lac; cell.CID = cid; return cell; } /** * 获取经纬度 * * @throws Exception */ private SItude getItude(SCell cell) throws Exception { SItude itude = new SItude(); /** 采用Android默认的HttpClient */ HttpClient client = new DefaultHttpClient(); /** 采用POST方法 */ HttpPost post = new HttpPost("http://www.google.com/loc/json"); try { /** 构造POST的JSON数据 */ JSONObject holder = new JSONObject(); holder.put("version", "1.1.0"); holder.put("host", "maps.google.com"); holder.put("address_language", "zh_CN"); holder.put("request_address", true); holder.put("radio_type", "gsm"); holder.put("carrier", "HTC"); JSONObject tower = new JSONObject(); tower.put("mobile_country_code", cell.MCC); tower.put("mobile_network_code", cell.MNC); tower.put("cell_id", cell.CID); tower.put("location_area_code", cell.LAC); JSONArray towerarray = new JSONArray(); towerarray.put(tower); holder.put("cell_towers", towerarray); StringEntity query = new StringEntity(holder.toString()); post.setEntity(query); /** 发出POST数据并获取返回数据 */ HttpResponse response = client.execute(post); HttpEntity entity = response.getEntity(); BufferedReader buffReader = new BufferedReader(new InputStreamReader(entity.getContent())); StringBuffer strBuff = new StringBuffer(); String result = null; while ((result = buffReader.readLine()) != null) { strBuff.append(result); } /** 解析返回的JSON数据获得经纬度 */ JSONObject json = new JSONObject(strBuff.toString()); JSONObject subjosn = new JSONObject(json.getString("location")); itude.latitude = subjosn.getString("latitude"); itude.longitude = subjosn.getString("longitude"); Log.i("Itude", itude.latitude + itude.longitude); } catch (Exception e) { Log.e(e.getMessage(), e.toString()); throw new Exception("获取经纬度出现错误:"+e.getMessage()); } finally{ post.abort(); client = null; } return itude; } /** * 获取地理位置 * * @throws Exception */ private String getLocation(SItude itude) throws Exception { String resultString = ""; /** 这里采用get方法,直接将参数加到URL上 */ String urlString = String.format("http://maps.google.cn/maps/geo?key=abcdefg&q=%s,%s", itude.latitude, itude.longitude); Log.i("URL", urlString); /** 新建HttpClient */ HttpClient client = new DefaultHttpClient(); /** 采用GET方法 */ HttpGet get = new HttpGet(urlString); try { /** 发起GET请求并获得返回数据 */ HttpResponse response = client.execute(get); HttpEntity entity = response.getEntity(); BufferedReader buffReader = new BufferedReader(new InputStreamReader(entity.getContent())); StringBuffer strBuff = new StringBuffer(); String result = null; while ((result = buffReader.readLine()) != null) { strBuff.append(result); } resultString = strBuff.toString(); /** 解析JSON数据,获得物理地址 */ if (resultString != null && resultString.length() > 0) { JSONObject jsonobject = new JSONObject(resultString); JSONArray jsonArray = new JSONArray(jsonobject.get("Placemark").toString()); resultString = ""; for (int i = 0; i < jsonArray.length(); i++) { resultString = jsonArray.getJSONObject(i).getString("address"); } } } catch (Exception e) { throw new Exception("获取物理位置出现错误:" + e.getMessage()); } finally { get.abort(); client = null; } return resultString; } /** 显示结果 */ private void showResult(SCell cell, String location,SItude itude) { TextView cellText = (TextView) findViewById(R.id.cellText); cellText.setText(String.format("基站信息:mcc:%d, mnc:%d, lac:%d, cid:%d", cell.MCC, cell.MNC, cell.LAC, cell.CID)); TextView locationText = (TextView) findViewById(R.id.lacationText); locationText.setText("物理位置:" + location); TextView itudeText=(TextView)findViewById(R.id.itudeText); itudeText.setText("经度:"+itude.latitude+" 纬度:"+itude.longitude); } class MyHandler extends Handler { public MyHandler() { } public MyHandler(Looper L) { super(L); } // 子类必须重写此方法,接管数据 @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub Log.d("MyHandler", "handleMessage......"); /** 显示结果 */ mProgressDialog.dismiss(); if(msg.arg1==1) { showResult(cell, location,itude); } super.handleMessage(msg); // 此处可以更新UI } } class MyThread implements Runnable { public void run() { Message msg = new Message(); msg.arg1=1; try { /** 获取基站数据 */ cell = getCellInfo(); /** 根据基站数据获取经纬度 */ itude = getItude(cell); /** 获取地理位置 */ location = getLocation(itude); /** 关闭对话框 */ msg.arg1=1; myHandler.sendMessage(msg); // 向Handler发送消息,更新UI } catch (InterruptedException e) { // TODO Auto-generated catch block /** 显示错误 */ TextView cellText = (TextView) findViewById(R.id.cellText); cellText.setText(e.getMessage()); Log.e("Error", e.getMessage()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } Log.d("thread.......", "mThread........"); } } }
发表评论
-
带你深入理解 FLUTTER 中的字体“冷”知识
2020-08-10 23:40 612本篇将带你深入理解 Flutter 开发过程中关于字体和文 ... -
Flutter -自定义日历组件
2020-03-01 17:56 1087颜色文件和屏幕适配的文件 可以自己给定 import ... -
Dart高级(一)——泛型与Json To Bean
2020-02-23 19:13 976从 Flutter 发布到现在, 越来越多人开始尝试使用 Da ... -
flutter loading、Progress进度条
2020-02-21 17:03 1132Flutter Progress 1 条形无固定值进度条 ... -
Flutter使用Https加载图片
2020-02-21 01:39 983Flutter使用Https加载图片 使用http加载图片出 ... -
flutter shared_preferences 异步变同步
2020-02-21 00:55 827前言 引用 在开发原生iOS或Native应用时,一般有判断上 ... -
Flutter TextField边框颜色
2020-02-19 21:31 911监听要销毁 myController.dispose(); T ... -
flutter Future的正确用法
2020-02-18 21:55 788在flutter中经常会用到异步任务,dart中异步任务异步处 ... -
记一次Flutter简单粗暴处理HTTPS证书检验方法
2020-02-18 14:13 921最近在做Flutter项目到了遇到一个无解的事情,当使用Ima ... -
flutter 获取屏幕宽度高度 通知栏高度等屏幕信息
2019-07-27 08:39 1306##MediaQuery MediaQuery.of(con ... -
关于flutter RefreshIndicator扩展listview下拉刷新的问题
2019-07-10 19:40 1058当条目过少时listview某些嵌套情况下可能不会滚动(条目 ... -
flutter listview 改变状态的时候一直无限添加
2019-07-10 16:01 721setstate的时候会一直无限的调用listview.bui ... -
Flutter Android端启动白屏问题的解决
2019-07-09 00:51 1478问题描述 Flutter 应用在 Android 端上启动时 ... -
Flutter中SnackBar使用
2019-07-08 23:43 742底部弹出,然后在指定时间后消失。 注意: build(Bui ... -
Flutter 之点击空白区域收起键盘
2019-07-08 18:43 1758点击空白处取消TextField焦点这个需求是非常简单的,在学 ... -
Flutter 弹窗 Dialog ,AlertDialog,IOS风格
2019-07-08 18:04 1349import 'package:flutter/mate ... -
flutter ---TextField 之 输入类型、长度限制
2019-07-08 14:30 2288TextField想要实现输入类型、长度限制需要先引入impo ... -
【flutter 溢出BUG】键盘上显示bottom overflowed by 104 PIXELS
2019-07-08 11:13 1517一开始直接使用Scaffold布局,body:new Colu ... -
解决Flutter项目卡在Initializing gradle...界面的问题
2019-07-07 12:53 842Flutter最近很火,我抽出了一点时间对Flutter进行了 ... -
关于android O 上 NotificationChannel 的一些注意事项
2019-07-04 11:47 921最近在适配android O,遇到个问题,应用中原本有设置界面 ...
相关推荐
以下是对"android 基站定位程序"这一主题的详细解释: 一、基站定位原理 基站定位依赖于手机接收到来自多个移动通信基站的信号强度。每个基站都有其唯一的识别码(Cell ID)和小区全球识别码(LAC),当手机连接到...
- `android GPS和基站定位程序及源码.rar`可能包含了一个完整的Android项目,演示了如何集成和使用GPS和基站定位功能。 - 可能包含的文件:Activity类,用于处理用户界面和定位逻辑;BroadcastReceiver,监听网络...
本文将详细介绍如何在Android平台上实现一个简单的基站定位程序。 首先需要理解基站定位的基本概念。基站定位主要依靠移动电话网络中的信号塔,通过获取手机当前连接的基站信息来估计位置。这些信息通常包括移动...
描述中的“symbian s60v3开发的实时定位程序”是指该程序是为诺基亚S60平台第三版(S60v3)设计的,这是一个基于塞班操作系统的老款智能手机平台。这个程序利用手机内置的GPS模块,当GPS不可用时,会切换到基站定位...
在Android系统中,基站定位是一种基于移动通信网络的定位方式,它通过获取手机与周围基站的距离来估算设备的位置。这种定位方法尤其适用于GPS信号不可用或者较弱的环境,如室内或城市高楼之间。本节将深入探讨...
6. **服务接口**:提供给应用程序调用的API,使得开发者可以在自己的应用中集成基站定位功能,如地图导航、位置服务等。 7. **安全性与隐私**:源码中还会包含确保用户数据安全和隐私保护的相关措施,例如匿名化...
在Android系统中,基站定位是一种常见的移动设备定位技术,它基于手机接收到来自周围基站的无线电信号强度来确定设备的位置。本压缩包"Android 基站定位源码.zip"包含了一个实现这一功能的源代码示例。下面将详细...
在Android平台上,百度基站定位是一种常见的地理定位方法,它结合了网络信号和GPS信号来获取设备的位置信息。本文将深入探讨这一技术,并基于提供的资源,包括相关jar包和示例项目,来阐述如何在Android应用中集成并...
通过理解并运用这些知识点,开发者可以在Android应用程序中实现3G基站定位功能,为用户提供位置服务,例如导航、周边服务查找等。这个完整的源码实例是一个很好的学习和参考资源,可以帮助开发者快速掌握基站定位...
基站定位是一种移动设备定位技术,尤其在GPS信号不强或者无法获取的情况下,它成为了一种重要的定位手段。本文将深入探讨基于Android系统的基站定位技术,包括其原理、实现方法以及如何利用提供的“帮助类.java”和...
### 移动通信基站定位系统知识点解析 #### 一、移动通信基站定位系统概述 **移动通信基站定位系统**是一种用于确定移动通信基站位置的技术体系。这类系统对于优化移动通信网络布局、提升通信服务质量至关重要。...
TestStationLocation可能是一个测试工具或程序,用于模拟基站定位过程,分析信号数据,或者进行定位算法的验证。使用这样的工具,开发者可以更好地理解和优化定位系统,例如调整算法参数,提升定位速度和精度,或者...
- 实施部分涉及了Web服务和J2ME应用程序的模型、视图和控制器的实现细节,这包括了如何在移动应用中整合基站定位的数据以及如何将用户的位置信息发送到远程的Web服务。 - 结果和结论部分则是对整个项目实施的结果的...
在“loc.zip_基站_基站定位_定位_手机定位”这个压缩包中,我们可以推测它包含了一个用于手机基站定位的程序或工具。 首先,基站定位的基本原理是通过测量手机与多个基站之间的信号强度和时延,根据三角定位法或者...
《基于STM32F103的基站定位测试工程详解》 在当今信息化社会,定位技术已经成为各种智能设备不可或缺的功能之一。本项目“基于STM32F103的基站定位测试工程”专注于利用SIM800C模块实现基站定位功能,通过微控制器...
这些代码通常会涉及网络通信、数据解码、定位算法等方面的知识,对于开发基于基站定位的应用程序非常有帮助。 需要注意的是,基站定位的精度受到基站密度、信号干扰等因素的影响,可能不如卫星定位那样精确。然而,...
在Android程序开发中,基站定位是一种常见的位置获取方式,它基于手机接收到的移动通信基站的信号强度来确定设备的位置。基站定位相比GPS定位,在室内或城市高楼区往往有更好的表现,因为基站信号不受天气影响且覆盖...