コード例 #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
  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;
  }