Esempio n. 1
0
  /**
   * 得到坐标群的中心点坐标
   *
   * @param list
   * @return
   */
  public LatLng getCenterPointer(List<MyPoint> list) {

    double maxLng = 0;
    double maxLat = 0;
    double minLng = 0;
    double minLat = 0;

    for (int i = 0; i < list.size(); i++) {
      double lat = list.get(i).getLat();
      double lng = list.get(i).getLng();
      if (i == 0) {
        minLat = maxLat = lat;
        minLng = maxLng = lng;
        continue;
      }

      if (minLat > lat) {
        minLat = lat;
      }
      if (minLng > lng) {
        minLng = lng;
      }
      if (maxLat < lat) {
        maxLng = lat;
      }
      if (maxLng < lng) {
        maxLng = lng;
      }
    }
    LatLng southwest = new LatLng(minLat, minLng);
    LatLng northeast = new LatLng(maxLat, maxLng);
    LatLngBounds bounds = new LatLngBounds.Builder().include(northeast).include(southwest).build();
    return bounds.getCenter();
  }
Esempio n. 2
0
  public void initOverlay() {
    // add marker overlay
    addOverlay(39.963175, 116.400244, R.drawable.icon_marka, 9);
    addOverlay(39.942821, 116.369199, R.drawable.icon_markb, 5);
    MarkerOptions ooC = (MarkerOptions) addOverlay(39.939723, 116.425541, R.drawable.icon_markc, 7);
    MarkerOptions ooD = (MarkerOptions) addOverlay(39.906965, 116.401394, R.drawable.icon_markd, 0);
    ooC.perspective(false).anchor(0.5f, 0.5f).rotate(30);
    ooD.period(10);

    //		ArrayList<BitmapDescriptor> giflist = new ArrayList<BitmapDescriptor>();
    //		giflist.add(bdA);
    //		giflist.add(bdB);
    //		giflist.add(bdC);

    BitmapDescriptor bd = BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding);
    mBitmapList.add(bd);
    // add ground overlay
    LatLng southwest = new LatLng(39.92235, 116.380338);
    LatLng northeast = new LatLng(39.947246, 116.414977);
    LatLngBounds bounds = new LatLngBounds.Builder().include(northeast).include(southwest).build();

    BitmapDescriptor bdGround = BitmapDescriptorFactory.fromResource(R.drawable.ground_overlay);

    mBitmapList.add(bdGround);
    OverlayOptions ooGround =
        new GroundOverlayOptions().positionFromBounds(bounds).image(bdGround).transparency(0.8f);
    mBaiduMap.addOverlay(ooGround);

    MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(bounds.getCenter());
    mBaiduMap.setMapStatus(u);

    mBaiduMap.setOnMarkerDragListener(
        new OnMarkerDragListener() {
          public void onMarkerDrag(Marker marker) {}

          public void onMarkerDragEnd(Marker marker) {
            Toast.makeText(
                    OverlayDemo.this,
                    "拖拽结束,新位置:"
                        + marker.getPosition().latitude
                        + ", "
                        + marker.getPosition().longitude,
                    Toast.LENGTH_LONG)
                .show();
          }

          public void onMarkerDragStart(Marker marker) {}
        });
  }