@Override
 public void onReceiveLocation(BDLocation location) {
   // TODO Auto-generated method stub
   if (null != location
       && (location.getLocType() == BDLocation.TypeGpsLocation
           || location.getLocType() == BDLocation.TypeNetWorkLocation)) {
     System.out.println(
         "================>" + location.getLocType() + BDLocation.TypeOffLineLocation);
     StringBuffer sb = new StringBuffer(256);
     sb.append("time : ");
     sb.append(location.getTime());
     sb.append("\nlatitude : ");
     sb.append(location.getLatitude());
     sb.append("\nlontitude : ");
     sb.append(location.getLongitude());
     sb.append("\naddr : ");
     sb.append(location.getAddrStr());
     System.out.println(sb.toString());
     // 第一次去的的经纬度
     firstLocationLatitude = location.getLatitude();
     firstLocationLongitude = location.getLongitude();
     // 设置位置
     MyLocationData locData =
         new MyLocationData.Builder()
             .accuracy(location.getRadius())
             .direction(10)
             .latitude(location.getLatitude())
             .longitude(location.getLongitude())
             .build();
     baiduMap.setMyLocationData(locData);
     // 更新位置、比例系数、添加标志等状态
     LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
     markFirstLocation();
     markClickLocation(latLng);
     // 更新地图状态
     MapStatus mapStatus = new MapStatus.Builder().target(latLng).zoom(16).build();
     MapStatusUpdate mapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mapStatus);
     baiduMap.animateMapStatus(mapStatusUpdate);
     // 检索
     geoCoder.reverseGeoCode(new ReverseGeoCodeOption().location(latLng));
     // 停止定位
     client.stop();
   } else {
     // 定位失败
     showToast("定位失败,请检查网络,重新定位");
     SelectLocationActivity.this.setResult(RESULT_CANCELED);
     SelectLocationActivity.this.finish();
   }
 }
Exemple #2
0
  @Override
  public boolean onMarkerClick(final Marker marker) {
    if (marker != null) {
      final LatLng latLng = marker.getPosition();
      if (latLng != null && mGeoCoder == null) {
        final ReverseGeoCodeOption reverseGeoCodeOption = new ReverseGeoCodeOption();
        reverseGeoCodeOption.location(latLng);

        mGeoCoder = GeoCoder.newInstance();
        mGeoCoder.setOnGetGeoCodeResultListener(this);
        if (!mGeoCoder.reverseGeoCode(reverseGeoCodeOption)) mGeoCoder = null;
      }
    }

    return false;
  }