In my android application I'm using routing and clustering in osmdroid but I'm not able to bound the LatLng like we do in google maps with latlngbounds.builder...
for example
LatLng longlat = new LatLng(lat, log);
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(longlat);
I want to do the same with osmdroid.
Google Maps LatLngBounds becomes BoundingBox in osmdroid (more or less).
It has no direct equivalent to the LatLngBounds.including method (yes, could be a good idea to implement this one).
But BoundingBox.fromGeoPoints covers a lot of needs.
{
IGeoPoint screenTopLeft = mapView.getProjection().fromPixels(0, 0);
IGeoPoint screenTopRight = mapView.getProjection().fromPixels(mapView.getWidth(), 0);
IGeoPoint screenBottomLeft = mapView.getProjection().fromPixels(0, mapView.getHeight());
List<IGeoPoint> iGeoPoints = new ArrayList<>();
iGeoPoints.add(screenTopRight);
iGeoPoints.add(screenTopLeft);
iGeoPoints.add(screenBottomLeft);
BoundingBox boundingBox = BoundingBox.fromGeoPoints(iGeoPoints);
if (boundingBox.contains(currentLocation.getLatitude(), currentLocation.getLongitude())) {
return true;
} else {
return false;
}
}
This will check whether current location is under bound or not.
Related
In google maps I want to fix my camera to a particular country. I don't need whole worlds Mercator projection. So I need to set LatLngBounds in my google maps. How can I find LatLngBounds of a particular region?
Here is my code but it's not setting LatLngBounds as my expectation set's constraints on right side.
LatLng v1= new LatLng(24.044982389517603,89.75482430309057);
LatLng v2 = new LatLng(22.309956868003045,91.20187237858772);
LatLngBounds BANGLADESH = new LatLngBounds(
v2,v1
);
mMap.setLatLngBoundsForCameraTarget(BANGLADESH);
You can get country boundaries once from openstreetmap.org like described in this article of PÄ“teris Å…ikiforovs or by http://polygons.openstreetmap.fr/get_poly.py?id=184640¶ms=0 and add it as polygon points find LatLngBounds like you do it:
...
Builder builder = new LatLngBounds.Builder();
for(int i = 0 ; i < N_POINTS; i++) {
builder.include(new LatLng(lat, lng));
}
LatLngBounds BANGLADESH = new LatLngBounds = builder.build();
int padding = 15; // offset from edges of the map in pixels
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(BANGLADESH, padding);
mMap.moveCamera(cameraUpdate );
...
I was trying to plot a heatmap on Android device using "Google Map" with the help of tutorial as described here on Google developers, using Android utility library
Using the sample code as described in the tutorial, I implemented the heatmap as below:
As you can see, the heat map locations are displayed in Green circles and dots, but actually, I wanted to achieve something like below:
That is connecting the heat map via a line to the current location.
Any idea or help?
You can use SphericalUtil.interpolate() from Google Maps Android API Utility Library to get additional points between your source points and sent it to HeatmapTileProvider to get "heat map line". For example, with this code:
#Override
public void onMapReady(GoogleMap googleMap) {
mGoogleMap = googleMap;
// Create the gradient.
int[] colors = {
Color.rgb(102, 225, 0), // green
Color.rgb(255, 0, 0) // red
};
float[] startPoints = {
0.2f, 1f
};
Gradient gradient = new Gradient(colors, startPoints);
final List<LatLng> sourcePolyPoints = new ArrayList<>();
sourcePolyPoints.add(new LatLng(28.537266, 77.208099));
sourcePolyPoints.add(new LatLng(28.536965, 77.209571));
sourcePolyPoints.add(new LatLng(28.536786, 77.209989));
sourcePolyPoints.add(new LatLng(28.537886, 77.210205));
sourcePolyPoints.add(new LatLng(28.537886, 77.210205));
final List<LatLng> interpolatedPolyPoints = new ArrayList<>();
for (int ixPoint = 0; ixPoint < sourcePolyPoints.size() - 1; ixPoint++) {
int nInterpolated = 50;
for (int ixInterpolated = 0; ixInterpolated < nInterpolated; ixInterpolated++) {
LatLng interpolatedPoint = SphericalUtil.interpolate(sourcePolyPoints.get(ixPoint),
sourcePolyPoints.get(ixPoint + 1), (double) ixInterpolated / (double) nInterpolated);
interpolatedPolyPoints.add(interpolatedPoint);
}
}
// Create the tile provider.
mProvider = new HeatmapTileProvider.Builder()
.data(interpolatedPolyPoints)
.gradient(gradient)
.build();
// Add the tile overlay to the map.
mOverlay = mGoogleMap.addTileOverlay(new TileOverlayOptions().tileProvider(mProvider));
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(28.536965, 77.209571), 16));
}
you get smooth "heatmap line" between your source points, like that:
You can adjust color and width of "heatmap line" by HeatmapTileProvider parameters. And if you need polyline only on road you can use Snap to Road part of Google Maps Roads API or examples provided in Waleed Asim comments.
I'm using google directions and make a route between two points and setting a marker and I need to set a window with some information in both of these markers, but According to google I just can show a window one at the time! But in Uber App they did with both points.
This is what I did :
public void drawRoute(){
PolylineOptions po;
if(polyline == null){
po = new PolylineOptions();
for(int i = 0, tam = latLngs.size(); i < tam; i++){
po.add(latLngs.get(i));
}
po.color(Color.BLACK).width(10);
polyline = mMap.addPolyline(po);
LatLng myCurrentLocation = new LatLng(lat, lon);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(myCurrentLocation, 11));
Marker mMarker;
mMarker = mMap.addMarker(new MarkerOptions().position(finalLocaltion).title(finalLocationName));
mMarker.showInfoWindow();
}
else{
polyline.setPoints(latLngs);
}
}
The window only appears when I click, and not by default!
Would it be possible to use a heat map to represent/show the amount of people in the specific area using google map v2?
If not , would there be other library or API that I can use to know represent the amount of people in the area.
reference that I saw on the internet: http://googlemapsmania.blogspot.com/2014/02/population-mapping.html
Hey here is the example how you can use heatmap and show your max population
Add all marker in your map then use this code.
HeatmapTileProvider mProvider;
TileOverlay mOverlay;
// Add your all lat lng inside this array list and pass it to addHeatMap
List<LatLng> list = new ArrayList<LatLng>();
double puLat = 0, puLng = 0;
private void createMarker() {
double cLat, cLng;
cLat = locationCur.getLatitude();
cLng = locationCur.getLongitude();
Marker testMarker = googleMap.addMarker(new MarkerOptions()
.position(new LatLng(cLat, cLng)).draggable(true)
.title("Demanding Areas").flat(false));
testMarker.showInfoWindow();
}
private void addHeatMap() {
mProvider = new HeatmapTileProvider.Builder().data(list).build();
mOverlay = googleMap.addTileOverlay(new TileOverlayOptions()
.tileProvider(mProvider));
}
Hope this will help you
I have a bunch of markers in which I load onto a google map. My problem is that, the camera is not ontop of the markers. Can I center it on top of all my markers?
I am adding my markers with this code:
for(int i = 0; i < jsonArray.length(); i++) {
String breweryName = jsonArray.getJSONObject(i).getString("brewery");
String lat = jsonArray.getJSONObject(i).getString("lat");
String lng = jsonArray.getJSONObject(i).getString("lng");
String bID = jsonArray.getJSONObject(i).getString("breweryID");
double latD = Double.parseDouble(lat);
double lngD = Double.parseDouble(lng);
m.addMarker(new MarkerOptions()
.position(new LatLng(latD, lngD))
.title(breweryName));
}
I looked on stack and found this question, which is the same as mine:
Android Google maps API V2 center markers
But there isnt much context behind it and am not sure how to implement it.
You can animate your camera within specific bounds. Let's say you have an ArrayList of markers, something like (this could also be a list of LatLngs, doubles, anything that contains the latitude/longitude for your marker)
List<MarkerOptions> markers = new ArrayList<MarkerOptions>();
You can then make sure they are all visible on your map by doing the following
LatLngBounds.Builder builder = new LatLngBounds.Builder();
LatLng position;
for(int i = 0; i < markers.size(); i++){
position = markers.get(i).getPosition();
builder.include(new LatLng(position.latitude, position.longitude));
}
LatLngBounds bounds = builder.build();
map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 15));