wifi 网络定位 方式
来源:互联网 发布:淘宝哪里可以领红包 编辑:程序博客网 时间:2024/04/28 11:50
package com.studio.android.chp08.ex01;import android.app.Activity;import android.content.Context;import android.content.Intent;import android.location.Criteria;import android.location.Location;import android.location.LocationListener;import android.location.LocationManager;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.TextView;public class CurrentLocation extends Activity { /** Called when the activity is first created. */ private Location local=null; private Location localBackup=null; private int i=0; /** * LocationListener 是一个接口 * new LocationListener() 去实例化这个接口 * new LocationListener() {}对接口的方法进行实现 * * 整体而言是个 成员变量 复制语句,可以放到 前面去 * 这个成员变量 是 LocationListener 类型 */ private final LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { updateWithNewLocation(location);//地址改变 //local=location; System.out.println("the onLocationChanged"); } public void onProviderDisabled(String provider){ updateWithNewLocation(null);//地址失效 System.out.println("the onProviderDisabled"); } public void onProviderEnabled(String provider){ System.out.println("the onProviderEnabled"); } public void onStatusChanged(String provider, int status,Bundle extras){ System.out.println("the onStatusChanged"); } }; public Location getLocal() {return local;}public void setLocal(Location local) {this.local = local;}@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //选择布局,用 main 里面的布局方式 Button btv=(Button)findViewById(R.id.GoSecond); LocationManager locationManager; String serviceName = Context.LOCATION_SERVICE; locationManager = (LocationManager)getSystemService(serviceName); // String provider = LocationManager.GPS_PROVIDER; String provider2= LocationManager.NETWORK_PROVIDER; localBackup = locationManager.getLastKnownLocation(provider2); if(localBackup!=null) updateWithNewLocation(localBackup); locationManager.requestLocationUpdates(provider2, 2000, 0, locationListener);//注册了监听器 btv.setOnClickListener(new View.OnClickListener(){public void onClick(View v) {// TODO 实现这个接口的方法Intent intent = new Intent();if(CurrentLocation.this.local!=null){double lati = CurrentLocation.this.local.getLatitude();double logti=CurrentLocation.this.local.getLongitude();intent.putExtra("Lati",lati);intent.putExtra("Lnti", logti);} intent.setClass(CurrentLocation.this, LocationName.class); startActivity(intent); } }); } private void updateWithNewLocation(Location location) { String latLongString; TextView myLocationText; myLocationText = (TextView)findViewById(R.id.myLocationText); if (location != null) { double lat = location.getLatitude(); double lng = location.getLongitude(); this.setLocal(location);//更新 本类的location System.out.println(" the lat is "+lat+" the lng is "+lng); latLongString = "第 "+ ++i+" 次 更新 纬度是:" + lat + "\n经度:" + lng; } else { latLongString = "无法获取地理信息"; } myLocationText.setText("您当前的位置是:\n" +latLongString); }}
误差在1m
- wifi 网络定位 方式
- 手机定位技术概述 利用GPS 网络 wifi 定位
- wifi定位
- wifi定位
- Android之手机定位方式(GPS定位,网络定位,基站定位)
- android定位之GPS,WIFI和GPRS(NETWORK)方式的定位(含实现源码)
- android 基站定位 wifi定位
- get方式网络请求+蓝牙状态判断+wifi状态判断
- 卫星定位、基站定位、wifi定位
- GPS定位、基站定位、wifi定位
- wifi定位技术
- wifi定位技术
- 添加wifi定位功能
- 添加wifi定位功能
- android WIFI定位
- wifi室内定位
- android 的wifi定位
- android 的wifi定位
- UDP
- hibernate的二级缓存
- 斯坦福CS基础课程教JavaScript
- Android图形系统的分析与移植--二、Android显示系统软件架构分析
- 生产excel和导出
- wifi 网络定位 方式
- 求余数(同余定理)
- 如何在win7使用notepad2替换notepad
- [转]Fedora 15搭建LAMP环境中可能遇到的问题
- couchDB 可以考虑用下文档数据库
- 将自编译安装的apache添加为linux系统服务
- (hdu 2035)人见人爱A^B
- maven2 插件库的bug
- Android图形系统分析与移植--三、内核空间显示功能介绍