基于百度地图3.1.1地位当前位置

来源:互联网 发布:网络安全保卫大队在哪 编辑:程序博客网 时间:2024/05/17 23:28
定位当前位置,可以去到当前位置的经纬度。
<pre code_snippet_id="622841" snippet_file_name="blog_20150318_2_6790037" name="code" class="java">public class MyLocationListenner implements BDLocationListener<span style="font-family: Arial, Helvetica, sans-serif;"></span>
{@Overridepublic void onReceiveLocation(BDLocation location){// map view 销毁后不在处理新接收的位置if(location == null || mMapView == null){return;}MyLocationData locData = new MyLocationData.Builder().accuracy(location.getRadius())// 此处设置开发者获取到的方向信息,顺时针0-360.direction(100).latitude(location.getLatitude()).longitude(location.getLongitude()).build();mBaiduMap.setMyLocationData(locData);if(isFirstLoc){isFirstLoc = false;LatLng ll = new LatLng(location.getLatitude(), location.getLongitude());MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);mBaiduMap.animateMapStatus(u);}location.setAddrStr("all");location.setSatelliteNumber(10);lat = location.getLatitude();lon = location.getLongitude();locationCity = location.getCity();locationAddress = location.getAddrStr();}}
</pre><pre code_snippet_id="622841" snippet_file_name="blog_20150318_5_8307700" name="code" class="java">
在之前要定位初始化
 // 定位初始化mLocClient = new LocationClient(this);LocationClientOption option = new LocationClientOption();option.setOpenGps(true);// 打开gpsoption.setCoorType("bd09ll"); // 设置坐标类型option.setScanSpan(1000);option.setIsNeedAddress(true);option.setLocationNotify(true);mLocClient.setLocOption(option);mLocClient.registerLocationListener(myListener);mLocClient.start();
                                             
0 0
原创粉丝点击