(五)GPRS定位的实现
- LocationManager alm = (LocationManager) this
- .getSystemService(Context.LOCATION_SERVICE);
- if (alm.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
- Toast.makeText(this, "GPS模块正常", Toast.LENGTH_SHORT).show();
- return;
- }
- Toast.makeText(this, "请开启GPS!", Toast.LENGTH_SHORT).show();
- Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
- startActivityForResult(intent, 0); // 此为设置完成后返回到获取界面
- locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
- gprs_view = (TextView) findViewById(R.id.gprs_view);
- Criteria criteria = new Criteria();
- // 获得最好的定位效果
- criteria.setAccuracy(Criteria.ACCURACY_COARSE);
- criteria.setAltitudeRequired(false);
- criteria.setBearingRequired(false);
- criteria.setCostAllowed(false);
- // 使用省电模式
- criteria.setPowerRequirement(Criteria.POWER_LOW);
- // 获得当前的位置提供者
- provider = locationManager.getBestProvider(criteria, false);
- ser.append(provider);
- locationManager.requestLocationUpdates(provider, 2000, 10, this);
- // 使用网络定位,获得上次定位的location对象
- if (location == null) {
- location = locationManager
- .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
- provider = LocationManager.NETWORK_PROVIDER;
- }
- String latLongString;
- if (location != null) {
- double lat = location.getLatitude();
- double lng = location.getLongitude();
- latLongString = "纬度:" + lat + "\n经度:" + lng;
- Geocoder gc = new Geocoder(context);
- List<Address> addresses = null;
- try {
- addresses = gc.getFromLocation(location.getLatitude(),
- location.getLongitude(), 1);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- ser.append("\n" + addresses.get(0).getCountryName());
- } else {
- latLongString = "无法获取地理信息";
- }
- ser.append("\n" + "您当前的位置是:\n" + latLongString);
- private void updateWithNewLocation(Location location) {
- // TODO Auto-generated method stub
- if (location == null) {
- locationManager.requestLocationUpdates(provider, 2000, (float) 0.1,
- this);
- }
- }
- <span style="font-size:18px;"> <application
- android:name="com.baidu.locSDK.test.Location"
- android:icon="@drawable/icon"
- android:label="@string/app_name" >
- <activity
- android:name="mainActivity"
- android:configChanges="orientation|keyboardHidden"
- android:label="@string/app_name" >
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <service
- android:name="com.baidu.location.f"
- android:enabled="true"
- android:process=":remote" >
- </service>
- </application>
- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
- <uses-permission android:name="android.permission.READ_PHONE_STATE" />
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
- <uses-permission android:name="android.permission.INTERNET" />
- <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
- <uses-permission android:name="android.permission.READ_LOGS" />
- <uses-permission android:name="android.permission.VIBRATE" /></span>
- mStartBtn.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- if (!mIsStart) {
- setLocationOption();
- mLocClient.start();
- mStartBtn.setText("开始");
- mIsStart = true;
- } else {
- mLocClient.stop();
- mIsStart = false;
- mStartBtn.setText("结束");
- }
- Log.d("locSDK_Demo1",
- "... mStartBtn onClick... pid=" + Process.myPid()
- + " count=" + count++);
- }
- });
- private void setLocationOption() {
- LocationClientOption option = new LocationClientOption();
- option.setOpenGps(mGpsCheck.isChecked()); // gps
- option.setCoorType(mCoorEdit.getText().toString());
- option.setAddrType(mAddrEdit.getText().toString());
- option.setScanSpan(Integer.parseInt(mSpanEdit.getText().toString()));
- mLocClient.setLocOption(option);
- }
- public void logMsg(String str) {
- try {
- mData = str;
- if ( mTv != null )
- mTv.setText(mData);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public class MyLocationListenner implements BDLocationListener {
- @Override
- public void onReceiveLocation(BDLocation location) {
- if (location == null)
- return ;
- StringBuffer sb = new StringBuffer(256);
- sb.append("time : ");
- sb.append(location.getTime());
- sb.append("\nerror code : ");
- sb.append(location.getLocType());
- sb.append("\nlatitude : ");
- sb.append(location.getLatitude());
- sb.append("\nlontitude : ");
- sb.append(location.getLongitude());
- sb.append("\nradius : ");
- sb.append(location.getRadius());
- if (location.getLocType() == BDLocation.TypeGpsLocation){
- sb.append("\nspeed : ");
- sb.append(location.getSpeed());
- sb.append("\nsatellite : ");
- sb.append(location.getSatelliteNumber());
- } else if (location.getLocType() == BDLocation.TypeNetWorkLocation){
- sb.append("\nprovince:");
- sb.append(location.getProvince());
- sb.append("\ncity");
- sb.append(location.getCity());
- sb.append("\nstreet");
- sb.append(location.getDistrict());
- sb.append("\naddr : ");
- sb.append(location.getAddrStr());
- }
- sb.append("\nsdk version : ");
- sb.append(mLocationClient.getVersion());
- logMsg(sb.toString());
- }
- public void onReceivePoi(BDLocation poiLocation) {
- if (poiLocation == null){
- return ;
- }
- StringBuffer sb = new StringBuffer(256);
- sb.append("Poi time : ");
- sb.append(poiLocation.getTime());
- sb.append("\nerror code : ");
- sb.append(poiLocation.getLocType());
- sb.append("\nlatitude : ");
- sb.append(poiLocation.getLatitude());
- sb.append("\nlontitude : ");
- sb.append(poiLocation.getLongitude());
- sb.append("\nradius : ");
- sb.append(poiLocation.getRadius());
- if (poiLocation.getLocType() == BDLocation.TypeNetWorkLocation){
- sb.append("\naddr : ");
- sb.append(poiLocation.getAddrStr());
- }
- if(poiLocation.hasPoi()){
- sb.append("\nPoi:");
- sb.append(poiLocation.getPoi());
- }else{
- sb.append("noPoi information");
- }
- logMsg(sb.toString());
- }
- }
(五)GPRS定位的实现相关推荐
- 做SEO优化第五步:定位目标关键词和长尾关键词
通常,我们在给网站选择关键词的时候除了要定位网站的目标关键词之外,还需要给网站选择几个长尾词,而且在优化的过程中,做好长尾关键词的排名也是非常重要的,当长尾词的排名上去了之后,也能够给网站带来可观的流 ...
- Android中GPRS定位的实现
前段时间在弄GPRS定位的问题,使用google的地图定位,大家也都知道,google现在在中国境内有很多限制,而且国外刷机严重,难免将google的各种服务给刷掉,所以最终采用百度的定位系统,完美实 ...
- Android中级第五讲--GPRS定位的实现
前段时间在弄GPRS定位的问题,使用google的地图定位,大家也都知道,google现在在中国境内有很多限制,而且国外刷机严重,难免将google的各种服务给刷掉,所以最终采用百度的定位系统,完美实 ...
- GPS/GPRS定位
闲着没事,把GPS模块的使用学习了一下,就是传说中的NMEA-0183,我只使用最小帧GPRMC(Recommended Minimum Specific GPS/TRANSIT Data),下图是我 ...
- iOS14 Widget开发踩坑(五)定位与地图的使用
iOS14 Widget开发踩坑(五)定位与地图的使用 前言 分析 实现案例 地图 定位 问题 适配黑暗模式 2022年12月15日已解决 中心点偏移问题 2022年12月19日已解决 延迟问题 本篇 ...
- CSS基础「五」定位
本篇文章为 CSS 基础系列笔记第五篇,参考 黑马程序员pink老师前端入门教程 其他CSS基础相关文章: CSS基础「一」基础选择器 / 字体属性 / 文本属性 / 三种样式表 CSS基础「二」复合 ...
- CSS基础: 五种定位以及定位叠放次序
前面看到浮动其实可以让某个盒子模块在某个位置,但是为什么还要右定位? 其实很简单,因为浮动有些定位是解决不了的,比如看下图: 在滑动的时候,你发现了没有,那就是标记的地方,拉动网页都在顶部和侧面,如果 ...
- LBS 和 GPRS 定位移动位置比较
名词释义: 基站定位一般应用于手机用户,手机基站定位服务又叫做移动位置服务(LBS--Location Based Service),它是通过电信移动运营商的网络(如 GSM 网)获取移动终端用户的位 ...
- python-selenum3 第五天定位——不常用定位与css定位详
使用tag来定位 tag定位的是标签,不常用 例如:百度的输入框标签是input 最终会报错,因为百度首页input标签太多了 driver = webdriver.Firefox(executabl ...
最新文章
- Oracle数据库相关命令
- Lucene教程具体解释
- 2022-03-19
- 【CV冬季划】终极进阶,超30个项目实战+3本书+3年知识星球
- python3连接mysql使用mysqldb_Python3 连接Mysql数据库
- javaone_JavaOne 2012:NetBeans.Next –未来路线图
- 在项目中使用fastreport_如何在项目管理中使用里程碑
- Debug和Realease版本的区别
- IT行业趋势前沿:SOA和开源
- python调用PostgreSQL 11
- PHP定界符的使用既注意事项
- asp.net的一些对话
- 重庆高清卫星地图(含道路标签数据叠加)
- itil 容量管理流程_ITIL的十个核心管理流程
- 华为防火墙配置(双机热备)
- Epub电子书格式(四)
- MapReducer Counter计数器的使用,Combiner ,Partitioner,Sort,Grop的使用,
- CENTOS6 安装配置 pptpd 心得
- android 全景拼接软件,这款全景图片拼接软件很强大
- 大数据时代的新闻变革
热门文章
- eBay电子商务模式
- 玩csgo笔记本配置要求是什么
- html5 射门小游戏,HTML5简单的投篮小游戏
- 快速了解helmet的使用
- 简单的系统登录设计思路【登陆界面设计】
- qt撤销与回退_Git版本控制教程 - Git查阅、撤销修改和版本回退
- 根据年龄, 来打印出当前年龄的人是少年(低于18), 青年(19-28), 中年(29-55), 老年(56以上)
- 【visum工作笔记】之九
- 城市出行半径大数据报告:一线城市通勤压力大 境外游最爱去泰国
- pandas链接mysql数据库读取和存入