@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);
  }
  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;
    }
  }
示例#3
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));
  }
示例#4
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 restoreMapState(MapInfo lastMapInfo) {
   LatLng center = new LatLng(lastMapInfo.getCenterX(), lastMapInfo.getCenterY());
   CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(center, lastMapInfo.getZoom());
   googleMap.moveCamera(cameraUpdate);
 }