定位当前位置,可以去到当前位置的经纬度。
<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>
{
@Override
public 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);// 打开gps
option.setCoorType("bd09ll"); // 设置坐标类型
option.setScanSpan(1000);
option.setIsNeedAddress(true);
option.setLocationNotify(true);
mLocClient.setLocOption(option);
mLocClient.registerLocationListener(myListener);
mLocClient.start();