コード例 #1
0
  @Override
  public void updateLocationMarker(Location location) {
    if (locationChangedListener != null) {
      currentUserLocation = location;
      locationChangedListener.onLocationChanged(location);
    }

    // Update clickable area
    LatLng userPosition = getUserLocation(location);
    if (userPositionClickArea == null) {
      MarkerOptions markerOptions = new MarkerOptions();
      markerOptions.position(userPosition);
      markerOptions.anchor(0.4f, 0.4f); // strange google maps bug
      markerOptions.icon(BitmapDescriptorFactory.fromBitmap(clickableBitmap));
      userPositionClickArea = googleMap.addMarker(markerOptions);
    } else {
      userPositionClickArea.setPosition(userPosition);
    }
    if (userPositionClickArea2 == null) {
      MarkerOptions markerOptions = new MarkerOptions();
      markerOptions.position(userPosition);
      markerOptions.anchor(0.6f, 0.6f); // strange google maps bug
      markerOptions.icon(BitmapDescriptorFactory.fromBitmap(clickableBitmap));
      userPositionClickArea2 = googleMap.addMarker(markerOptions);
    } else {
      userPositionClickArea2.setPosition(userPosition);
    }
  }
コード例 #2
0
  public void updateMarkerLocation(double lat, double lng) {
    LatLng location = new LatLng(lat, lng);

    if (marker == null) {
      markerOptions = new MarkerOptions();
      markerOptions.visible(true);
      markerOptions.position(location);
      markerOptions.draggable(draggable);
      marker = googleMap.addMarker(markerOptions);
    }

    CameraPosition cameraPosition =
        new CameraPosition.Builder().target(location).zoom(zoomLevel).bearing(0).tilt(45).build();
    googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
    marker.setPosition(location);
  }
コード例 #3
0
  private MarkerOptions createMarker(ReadableMap markerJson) {
    MarkerOptions options = new MarkerOptions();
    options.position(
        new LatLng(
            markerJson.getMap("coordinates").getDouble("lat"),
            markerJson.getMap("coordinates").getDouble("lng")));

    if (markerJson.hasKey("title")) {
      options.title(markerJson.getString("title"));
    }
    if (markerJson.hasKey("color")) {
      options.icon(BitmapDescriptorFactory.defaultMarker((float) markerJson.getDouble("color")));
    }
    if (markerJson.hasKey("snippet")) {
      options.snippet(markerJson.getString("snippet"));
    }
    if (markerJson.hasKey("icon")) {
      String varName = "";
      ReadableType iconType = markerJson.getType("icon");
      if (iconType.compareTo(ReadableType.Map) >= 0) {
        ReadableMap icon = markerJson.getMap("icon");
        try {
          int resId = getResourceDrawableId(icon.getString("uri"));
          Bitmap image = BitmapFactory.decodeResource(reactContext.getResources(), resId);

          options.icon(
              BitmapDescriptorFactory.fromBitmap(
                  Bitmap.createScaledBitmap(
                      image, icon.getInt("width"), icon.getInt("height"), true)));
        } catch (Exception e) {
          varName = icon.getString("uri");
        }
      } else if (iconType.compareTo(ReadableType.String) >= 0) {
        varName = markerJson.getString("icon");
      }
      if (!varName.equals("")) {
        // Changing marker icon to use resource
        int resourceValue = getResourceDrawableId(varName);
        Log.i(REACT_CLASS, varName + markerJson.toString());
        options.icon(BitmapDescriptorFactory.fromResource(resourceValue));
      }
    }
    if (markerJson.hasKey("anchor")) {
      ReadableArray anchor = markerJson.getArray("anchor");
      options.anchor((float) anchor.getDouble(0), (float) anchor.getDouble(1));
    }
    return options;
  }
コード例 #4
0
  public void addMarkers(List<GridPoint> gridPointList, List<PointEntity> pointEntityList) {
    clearMap();
    Marker m;
    LatLngBounds.Builder builder = new LatLngBounds.Builder();

    for (GridPoint gridPoint : gridPointList) {
      Bitmap icon =
          gridPoint.getScore() > 10
              ? gridPoint.getScore() > 20
                  ? BitmapFactory.decodeResource(getResources(), R.drawable.red_dot)
                  : BitmapFactory.decodeResource(getResources(), R.drawable.yellow_dot)
              : BitmapFactory.decodeResource(getResources(), R.drawable.green_dot);
      float hue =
          gridPoint.getScore() > 10
              ? gridPoint.getScore() > 20
                  ? BitmapDescriptorFactory.HUE_RED
                  : BitmapDescriptorFactory.HUE_YELLOW
              : BitmapDescriptorFactory.HUE_GREEN;

      markerOptions = new MarkerOptions();
      markerOptions.visible(true);
      markerOptions.position(
          new LatLng(
              gridPoint.getLocation().getLatitude().doubleValue(),
              gridPoint.getLocation().getLongitude().doubleValue()));
      markerOptions.draggable(false);
      markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
      // markerOptions.icon(BitmapDescriptorFactory.defaultMarker(hue));

      m = googleMap.addMarker(markerOptions);
      gridMap.put(m.getId(), gridPoint);
      builder.include(m.getPosition());
    }

    for (PointEntity pointEntity : pointEntityList) {
      Bitmap icon =
          pointEntity.getPointType().equals(PointType.PERSON)
              ? BitmapFactory.decodeResource(getResources(), R.drawable.man)
              : pointEntity.getPointType().equals(PointType.POLICE_STATION)
                  ? BitmapFactory.decodeResource(getResources(), R.drawable.police)
                  : BitmapFactory.decodeResource(getResources(), R.drawable.hospital);
      markerOptions = new MarkerOptions();
      markerOptions.visible(true);
      markerOptions.position(
          new LatLng(
              pointEntity.getLocation().getLatitude().doubleValue(),
              pointEntity.getLocation().getLongitude().doubleValue()));
      markerOptions.draggable(false);
      markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));

      m = googleMap.addMarker(markerOptions);
      pointMap.put(m.getId(), pointEntity);
      builder.include(m.getPosition());
    }

    if (gridPointList.size() > 1) {
      LatLngBounds bounds = builder.build();
      CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 0);
      googleMap.animateCamera(cu);
    } else if (gridPointList.size() > 0) {
      CameraPosition cameraPosition =
          new CameraPosition.Builder()
              .target(
                  new LatLng(
                      gridPointList.get(0).getLocation().getLatitude().doubleValue(),
                      gridPointList.get(0).getLocation().getLongitude().doubleValue()))
              .zoom(zoomLevel)
              .bearing(0)
              .tilt(45)
              .build();
      googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
    }

    markersDisplayed = true;
    heatmapDisplayed = false;
    clusterDisplayed = false;
  }