public void showMyLocationButton() {
   if (googleMap != null) {
     UiSettings uiSettings = googleMap.getUiSettings();
     googleMap.setMyLocationEnabled(true);
     uiSettings.setMyLocationButtonEnabled(true);
   }
 }
  @Override
  public void onMapReady(GoogleMap map) {
    //        LatLng sydney = new LatLng(-33.867, 151.206);
    //
    this.map = map;
    map.setMyLocationEnabled(true);
    map.moveCamera(
        CameraUpdateFactory.newLatLngZoom(new LatLng(START_LATITUDE, START_LONGITUDE), 13));
    //        map.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));
    //
    //        map.addMarker(new MarkerOptions()
    //                .title("Sydney")
    //                .snippet("The most populous city in Australia.")
    //                .position(sydney));
    scheduleTaskExecutor = Executors.newScheduledThreadPool(1);

    scheduleTaskExecutor.scheduleAtFixedRate(
        new Runnable() {
          public void run() {
            LatLong nextLocation = getNextLocation();
            Log.d(LOG_TAG, "Pushing location: " + nextLocation);
            mock.pushLocation(nextLocation);
            // Log.d(LOG_TAG, getMap().addMarker(new MarkerOptions().position(new
            // LatLng(nextLocation.lat, nextLocation.lng))).toString());
          }
        },
        0,
        1,
        TimeUnit.SECONDS);
  }
  @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);
    }
  }
  public void addHeatMap(List<GridPoint> gridPointList) {
    clearMap();
    List<LatLng> list = new ArrayList<LatLng>();
    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    LatLng latLng = null;

    for (GridPoint gridPoint : gridPointList) {
      latLng =
          new LatLng(
              gridPoint.getLocation().getLatitude().doubleValue(),
              gridPoint.getLocation().getLongitude().doubleValue());
      list.add(latLng);
      builder.include(latLng);
    }

    if (list.size() < 1) {
      return;
    }

    mProvider = new HeatmapTileProvider.Builder().data(list).build();
    mOverlay = googleMap.addTileOverlay(new TileOverlayOptions().tileProvider(mProvider));

    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(latLng).zoom(zoomLevel).bearing(0).tilt(45).build();
      googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
    }
    markersDisplayed = false;
    heatmapDisplayed = true;
    clusterDisplayed = false;
  }
  @Override
  public void onMapReady(final GoogleMap googleMap) {
    this.googleMap = googleMap;
    googleMap.setMyLocationEnabled(true);
    if (callback != null) {
      callback.onMapReady(googleMap);
    }
    if (cameraChangeListener != null) {
      googleMap.setOnCameraChangeListener(cameraChangeListener);
    }
    googleMap.setOnMarkerDragListener(
        new GoogleMap.OnMarkerDragListener() {
          @Override
          public void onMarkerDragStart(Marker arg0) {}

          @SuppressWarnings("unchecked")
          @Override
          public void onMarkerDragEnd(Marker arg0) {
            googleMap.animateCamera(CameraUpdateFactory.newLatLng(arg0.getPosition()));
          }

          @Override
          public void onMarkerDrag(Marker arg0) {}
        });
  }
Example #6
0
  @Override
  public void onMapReady(GoogleMap map) {
    Double latitude = Double.valueOf(data.getLatitude());
    Double longitude = Double.valueOf(data.getLongitude());

    LatLng CurrentLocation = new LatLng(latitude, longitude);

    map.setMyLocationEnabled(true);
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(CurrentLocation, 13));

    map.addMarker(
        new MarkerOptions()
            .title("Current Location")
            .snippet("Most Recent Location")
            .position(CurrentLocation));
  }
  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);
  }
  private Boolean updateMarkers(ReadableArray markerArray) {
    try {
      // First clear all markers from the map
      for (Marker marker : mapMarkers) {
        marker.remove();
      }
      mapMarkers.clear();
      markerLookup.clear();

      // All markers to map
      for (int i = 0; i < markerArray.size(); i++) {
        ReadableMap markerJson = markerArray.getMap(i);
        if (markerJson.hasKey("coordinates")) {
          Marker marker = map.addMarker(createMarker(markerJson));

          if (markerJson.hasKey("id")) {
            // As we have to lookup it either way, switch it around
            markerLookup.put(marker.getId(), markerJson.getString("id"));
            markerLookup.put(markerJson.getString("id"), marker.getId().replace("m", ""));
          }

          mapMarkers.add(marker);

        } else break;
      }

      return true;
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
  }
 public void setZoomLevel(int zoomLevel) {
   this.zoomLevel = zoomLevel;
   if (googleMap != null) {
     CameraUpdate zoom = CameraUpdateFactory.zoomTo(this.zoomLevel);
     googleMap.animateCamera(zoom);
   }
 }
  @Override
  public void setupMyLocationLayer() {
    googleMap.setMyLocationEnabled(true);
    googleMap.setLocationSource(
        new LocationSource() {

          @Override
          public void activate(OnLocationChangedListener onLocationChangedListener) {
            locationChangedListener = onLocationChangedListener;
          }

          @Override
          public void deactivate() {
            locationChangedListener = null;
          }
        });
  }
  public GoogleMapWrapper(Context context, GoogleMap map) {
    this.context = context;
    googleMap = map;
    googleMap.getUiSettings().setMyLocationButtonEnabled(true);
    googleMap.getUiSettings().setRotateGesturesEnabled(false);
    googleMap.getUiSettings().setTiltGesturesEnabled(false);
    googleMap.getUiSettings().setZoomControlsEnabled(true);

    // clickableBitmap.eraseColor(Color.RED);

    map.setOnMarkerClickListener(
        new GoogleMap.OnMarkerClickListener() {
          @Override
          public boolean onMarkerClick(Marker marker) {
            return onLocationMarkerTap(marker) || onMarkerTap(marker);
          }
        });
  }
 public Boolean centreMapAt(double lat, double lng) {
   if (googleMap != null) {
     LatLng location = new LatLng(lat, lng);
     CameraPosition cameraPosition =
         new CameraPosition.Builder().target(location).zoom(zoomLevel).bearing(0).tilt(45).build();
     googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
     return true;
   }
   return false;
 }
 public void addMarker(ReadableMap config) {
   MarkerOptions options = createMarker(config);
   Marker marker = map.addMarker(options);
   mapMarkers.add(marker);
   if (config.hasKey("id")) {
     // As we have to lookup it either way, switch it around
     markerLookup.put(marker.getId(), config.getString("id"));
     markerLookup.put(config.getString("id"), marker.getId().replace("m", ""));
   }
 }
 @Override
 public void setViewPortChangeListener(final ViewPortChangeListener listener) {
   googleMap.setOnCameraChangeListener(
       new OnCameraChangeListener() {
         @Override
         public void onCameraChange(CameraPosition cameraPosition) {
           GoogleMapWrapper.this.onCameraChange(cameraPosition, listener);
         }
       });
 }
 public void disableGestures() {
   UiSettings uiSettings = googleMap.getUiSettings();
   uiSettings.setMyLocationButtonEnabled(false);
   uiSettings.setTiltGesturesEnabled(false);
   uiSettings.setZoomGesturesEnabled(false);
   uiSettings.setZoomControlsEnabled(false);
   uiSettings.setRotateGesturesEnabled(false);
   uiSettings.setMyLocationButtonEnabled(false);
   uiSettings.setScrollGesturesEnabled(false);
   uiSettings.setCompassEnabled(false);
 }
  @Override
  public void updateMapLayer() {
    MapType mapType = Controller.getInstance().getPreferencesManager().getMapType();
    if (mapType == currentMapType) return;
    currentMapType = mapType;

    if (customTileOverlay != null) customTileOverlay.remove();
    customTileOverlay = null;

    switch (mapType) {
      case GoogleNormal:
        googleMap.setMapType(MAP_TYPE_NORMAL);
        return;
      case GoogleSatellite:
        googleMap.setMapType(MAP_TYPE_SATELLITE);
        return;
      case GoogleTerrain:
        googleMap.setMapType(MAP_TYPE_TERRAIN);
        return;
      case GoogleHybrid:
        googleMap.setMapType(MAP_TYPE_HYBRID);
        return;
    }

    googleMap.setMapType(MAP_TYPE_NONE); // Don't display any google layer

    UrlTileProvider provider = getTileProvider(mapType);
    if (provider != null) {
      customTileOverlay = googleMap.addTileOverlay(new TileOverlayOptions().tileProvider(provider));
      customTileOverlay.setZIndex(-100);
    }
  }
  public void addCluster(List<GridPoint> complaintDtos) {
    clearMap();
    GoogleMapCluster googleMapCluster;
    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    ClusterManager<GoogleMapCluster> mClusterManager;
    mClusterManager = new ClusterManager<GoogleMapCluster>(getActivity(), googleMap);
    googleMap.setOnCameraChangeListener(mClusterManager);
    googleMap.setOnMarkerClickListener(mClusterManager);
    for (GridPoint complaintDto : complaintDtos) {
      googleMapCluster =
          new GoogleMapCluster(
              complaintDto.getLocation().getLatitude().doubleValue(),
              complaintDto.getLocation().getLongitude().doubleValue());
      mClusterManager.addItem(googleMapCluster);
      builder.include(googleMapCluster.getPosition());
    }

    if (complaintDtos.size() > 1) {
      LatLngBounds bounds = builder.build();
      CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 0);
      googleMap.animateCamera(cu);
    } else if (complaintDtos.size() > 0) {
      CameraPosition cameraPosition =
          new CameraPosition.Builder()
              .target(
                  new LatLng(
                      complaintDtos.get(0).getLocation().getLatitude().doubleValue(),
                      complaintDtos.get(0).getLocation().getLongitude().doubleValue()))
              .zoom(zoomLevel)
              .bearing(0)
              .tilt(45)
              .build();
      googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
    }
    markersDisplayed = false;
    heatmapDisplayed = false;
    clusterDisplayed = true;
  }
 protected void onCameraChange(CameraPosition cameraPosition, ViewPortChangeListener listener) {
   // If custom tile overlay is enabled, use rounded zoom to avoid
   // tiles blurring
   if (customTileOverlay != null) {
     int roundZoom = Math.round(cameraPosition.zoom);
     if (Math.abs(cameraPosition.zoom - roundZoom) > 0.01) {
       CameraUpdate cameraUpdate = CameraUpdateFactory.zoomTo(roundZoom);
       googleMap.animateCamera(cameraUpdate);
       return;
     }
   }
   GeoRect viewPort = getViewPortGeoRect();
   listener.onViewPortChanged(viewPort);
 }
  private Boolean zoomOnMarkers() {
    try {
      int padding = 150;

      LatLngBounds.Builder builder = new LatLngBounds.Builder();
      for (Marker marker : mapMarkers) {
        builder.include(marker.getPosition());
      }
      LatLngBounds bounds = builder.build();

      CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
      map.animateCamera(cu);
      return true;
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
  }
  private Boolean updateCenter() {
    WritableMap properties = getProperties();
    if (properties.hasKey(PROP_CENTER)) {
      try {
        CameraUpdate cameraUpdate;

        Double lng = properties.getMap(PROP_CENTER).getDouble("lng");
        Double lat = properties.getMap(PROP_CENTER).getDouble("lat");

        if (properties.hasKey(PROP_ZOOM_LEVEL)) {
          int zoomLevel = properties.getInt(PROP_ZOOM_LEVEL);
          mlastZoom = zoomLevel;
          Log.i(REACT_CLASS, "Zoom: " + Integer.toString(properties.getInt(PROP_ZOOM_LEVEL)));
          cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), zoomLevel);
        } else {
          Log.i(REACT_CLASS, "Default Zoom.");
          /*
           * Changed from cameraUpdate = CameraUpdateFactory.newLatLng(new LatLng(lat, lng));
           * as it gave me "zoom" Bugs (defaulted to zoom factor 2) as soon as I put in
           * "real" LNG and LAT values...
           */
          cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), mlastZoom);
        }

        map.animateCamera(cameraUpdate);

        return true;
      } catch (Exception e) {
        // ERROR!
        e.printStackTrace();
        return false;
      }
    } else {
      return false;
    }
  }
Example #21
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.position);
    GoogleMap map =
        ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    final Geocoder geocoder = new Geocoder(this, Locale.getDefault());
    final Button submit = (Button) findViewById(R.id.position_submit_button);
    submit.setEnabled(false);
    userProfile = ProfileManager.getInstance();

    Toast.makeText(getApplicationContext(), "Press and Hold Pin to Move", Toast.LENGTH_LONG).show();

    LatLng pgh = new LatLng(40.441814, -80.012794);
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(pgh, 13));
    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

    if (locationManager != null) {
      boolean gpsIsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
      boolean networkIsEnabled =
          locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
      if (gpsIsEnabled) {
        Log.d("GPS Enabled", "GPS Enabled");
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000L, 10F, this);
        Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        if (location != null) {
          pgh = new LatLng(location.getLatitude(), location.getLongitude());
        }
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(pgh, 16));
        myIncident.setLat(Double.toString(pgh.latitude));
        myIncident.setLon(Double.toString(pgh.longitude));
        List<Address> addresses = null;
        try {
          addresses = geocoder.getFromLocation(pgh.latitude, pgh.longitude, 1);
          myIncident.setAddress(addresses.get(0).getAddressLine(0));
          city = addresses.get(0).getAddressLine(1);
          if (!city.contains("Pittsburgh")) {
            submit.setEnabled(false);
          } else {
            submit.setEnabled(true);
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
      } else {
        if (networkIsEnabled) {
          Log.d("Network Position Enabled", "Network Position");
          locationManager.requestLocationUpdates(
              LocationManager.NETWORK_PROVIDER, 5000L, 10F, this);
          Location location =
              locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
          if (location != null) {
            pgh = new LatLng(location.getLatitude(), location.getLongitude());
          }
          map.moveCamera(CameraUpdateFactory.newLatLngZoom(pgh, 15));
          myIncident.setLat(Double.toString(pgh.latitude));
          myIncident.setLon(Double.toString(pgh.longitude));
          List<Address> addresses = null;
          try {
            addresses = geocoder.getFromLocation(pgh.latitude, pgh.longitude, 1);
            myIncident.setAddress(addresses.get(0).getAddressLine(0));
            city = addresses.get(0).getAddressLine(1);
            if (!city.contains("Pittsburgh")) {
              submit.setEnabled(false);
            } else {
              submit.setEnabled(true);
            }
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }

    } else {

    }

    Marker issueLoc =
        map.addMarker(
            new MarkerOptions()
                .title("Issue Location")
                .snippet("Drag to Problem Location")
                .position(pgh)
                .draggable(true));

    map.setOnMarkerDragListener(
        new GoogleMap.OnMarkerDragListener() {
          @Override
          public void onMarkerDragStart(Marker marker) {}

          @Override
          public void onMarkerDrag(Marker marker) {}

          @Override
          public void onMarkerDragEnd(Marker marker) {
            double latitude = marker.getPosition().latitude;
            double longitude = marker.getPosition().longitude;
            myIncident.setLat(Double.toString(latitude));
            myIncident.setLon(Double.toString(longitude));
            List<Address> addresses = null;
            try {
              addresses = geocoder.getFromLocation(latitude, longitude, 1);
              myIncident.setAddress(addresses.get(0).getAddressLine(0));
              city = addresses.get(0).getAddressLine(1);
              if (!city.contains("Pittsburgh")) {
                submit.setEnabled(false);
              } else {
                submit.setEnabled(true);
              }
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        });
    submit.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            new uploadReport().execute();
          }
        });
  }
 @Override
 public void animateToGeoPoint(LatLng geoPoint) {
   LatLng center = new LatLng(geoPoint.latitude, geoPoint.longitude);
   googleMap.animateCamera(CameraUpdateFactory.newLatLng(center));
 }
 @Override
 public void animateToLocation(Location location) {
   LatLng center = new LatLng(location.getLongitude(), location.getLongitude());
   googleMap.animateCamera(CameraUpdateFactory.newLatLng(center));
 }
 @Override
 public MapInfo getMapState() {
   CameraPosition cameraPosition = googleMap.getCameraPosition();
   return new MapInfo(
       cameraPosition.target.latitude, cameraPosition.target.longitude, cameraPosition.zoom);
 }
 public void removeCluster() {
   googleMap.clear();
   googleMap.setOnCameraChangeListener(null);
   googleMap.setOnMarkerClickListener(null);
 }
 @Override
 public void restoreMapState(MapInfo lastMapInfo) {
   LatLng center = new LatLng(lastMapInfo.getCenterX(), lastMapInfo.getCenterY());
   CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(center, lastMapInfo.getZoom());
   googleMap.moveCamera(cameraUpdate);
 }
 public void removeMarkers() {
   googleMap.clear();
   gridMap.clear();
 }
  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;
  }
 @Override
 public void setZoomControlsEnabled(boolean zoomControlEnabled) {
   googleMap.getUiSettings().setZoomControlsEnabled(zoomControlEnabled);
 }
 public double getMarkedLongitude() {
   return googleMap.getCameraPosition().target.longitude;
 }