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(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); }
public void setZoomLevel(int zoomLevel) { this.zoomLevel = zoomLevel; if (googleMap != null) { CameraUpdate zoom = CameraUpdateFactory.zoomTo(this.zoomLevel); googleMap.animateCamera(zoom); } }
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 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 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; } }
@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 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; } }
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(); } }); }
@Override public void restoreMapState(MapInfo lastMapInfo) { LatLng center = new LatLng(lastMapInfo.getCenterX(), lastMapInfo.getCenterY()); CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(center, lastMapInfo.getZoom()); googleMap.moveCamera(cameraUpdate); }
@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)); }