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
Related
I want to show distance of each connected node on polyline. Currently i am not getting such method to show the text over polyline. Please help is it possible to do in android google maps api.
This method (Java) adds a polyline to the map and adds the distance of each segment as text on the polyline - using the referenced method in another answer for displaying the text.
private void polylineLabels() {
LatLng pt1 = new LatLng(39.935484,-83.023490);
LatLng pt2 = new LatLng(39.098487,-84.446861);
LatLng pt3 = new LatLng(39.743435,-86.104479);
LatLng pt4 = new LatLng(38.202789,-85.739295);
LatLng pt5 = new LatLng(38.614276,-90.138124);
routePts.add(pt1);
routePts.add(pt2);
routePts.add(pt3);
routePts.add(pt4);
routePts.add(pt5);
for (int i = 1; i < routePts.size(); i++) {
Polyline line = mMap.addPolyline(
new PolylineOptions()
.add(routePts.get(i-1), routePts.get(i)).
width(5).color(Color.RED));
double d = SphericalUtil.computeDistanceBetween(routePts.get(i-1),routePts.get(i));
int dInt = (int)d;
String msg = Integer.toString(dInt)+"m";
LatLng midpt = SphericalUtil.interpolate(routePts.get(i-1),routePts.get(i), 0.5);
Marker m = addText(this, mMap, midpt, msg, 2, 18);
}
}
And the result:
You'll have to experiment with offset location to better position each label.
Here's the answer which defines the addText method: https://stackoverflow.com/a/30185289/2711811 .
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.
Hi guys and girls if any :))
this piece of code creates a null pointer exception
I would like to put a couple of markers in MO
LAT = Double.parseDouble(PartA);
LNG = Double.parseDouble(PartB);
LatLng Standort = new LatLng(LAT, LNG);
MO[y] = mMap.addMarker(new MarkerOptions()
.position(Standort)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.kreis)));
builder.include(MO[y].getPosition());
Array type expected - found com.google.android.gms.maps.model.maker
Definition private static Marker MOrt = null;
I don't know my answer help you out or not.
First of all declare array , than add points and for adding marker i just start a loop with add marker function.
LatLng[] point_new = new LatLng[3];
point_new[0] = new LatLng(24.8926596, 67.0835093);
point_new[1] = new LatLng(48.85837,2.294481);
point_new[2] = new LatLng(0, 0);
for (int i = 0; i < point_new.length; i++) {
drawMarker(point_new[i]);
}
//drawMarker method
private void drawMarker(LatLng point) {
// Creating an instance of MarkerOptions
MarkerOptions markerOptions = new MarkerOptions();
// Setting latitude and longitude for the marker
markerOptions.position(point);
// Adding marker on the Google Map
map.addMarker(markerOptions);
}
final output
hope this will help!
Happy coding
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));
i have a set of lat long coordinates. i want to display all of those markers at a time on google map. I know how to display a single marker. But don't know how to display multiples at once. Anybody please help me.
Thank you.
i have lat long points.
like
id = 123 lat = 12.00 lon = 77.00
id = 124 lat = 12.01 lon = 77.01
etc.
May This Help You
for(int pin=0; pin<pins.size(); pin++)
{
LatLng pinLocation = new LatLng(Float.parseFloat(pins.get(pin).latitude), Float.parseFloat(pins.get(pin).longitude));
Marker storeMarker = map.addMarker(new MarkerOptions()
.position(pinLocation)
.title(pins.get(pin).pinname)
.snippet(pins.get(pin).address)
);
}
Try this:
LatLng one = new LatLng(2.40744, 77.014702);//Latitude and long points
LatLng two = new LatLng(2.407440, 77.014702);
.......
Similarly u can use more lat and long
myMarkerOne = gm.addMarker(new MarkerOptions()
.position(one)//use LatLng obj
.title("C")
.snippet("dsfd")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
myMarkerTwo = gm.addMarker(new MarkerOptions()
.position(two)
.title("C")
.snippet("dsfds")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
refer this: How to add multiple marker and overlay in v2 google map?
Also check this link:
Create a LatLng object by using following format:
LatLng location = new LatLng(latitude, longitude);
Then call the method with your LatLng object along with your GoogleMap object:
private Marker setCurrentLocation(LatLng location, GoogleMap map) {
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory
.fromResource(R.drawable.user_location_pin);
Marker marker = map.addMarker(new MarkerOptions().position(location)
.icon(bitmapDescriptor).title(location.toString()));
return marker;
}