@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);
    }
  }
  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 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 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);
  }
  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
  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();
          }
        });
  }