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;
}
Related
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
In onMapReady I am defining a few markers
First I declare the marker and his icon that is common for all markers and then each marker with it's own attributes. The problem is that when I declare the marker I cannot declare it as Marker beerMarker = new Marker() options as it makes me cast the Marker into MarkerOptions. What I would like is to call the info window for every marker but I cant as the beerMarker.showInfoWindow() is not acceptable for MarkerOptions. What am I doing wrong and what are the alternatives?
MarkerOptions beerMarker = new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.beer_marker));
//Carciuma
LatLng carciuma = new LatLng(43.604892, 1.476562);
mMap.addMarker(beerMarker.position(carciuma).title("Carciuma"));
//Boca
LatLng boca = new LatLng(43.604496, 1.474924);
mMap.addMarker(beerMarker.position(boca).title("Boca"));
//Bar Acasa
LatLng barAcasa = new LatLng(43.604781, 1.474502);
mMap.addMarker(beerMarker.position(barAcasa).title("Bar Acasa"));
Here is the updated version of the marker that meens I have t have to add for every individual marker the same icon, no?
LatLng barAcasa = new LatLng(43.604781, 1.474502);
Marker beerMarkerAcasa = mMap.addMarker(new MarkerOptions()
.position(barAcasa)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
.title("Bar Acasa"));
beerMarkerAcasa.showInfoWindow();
You can get this way Marker marker = mMap.addMarker(markeroption);
you can pass marker option for particulate marker in addMarker() method, they return marker instance which you can use.
I have a Google Maps API Activity and want the markes only to be clickable if the user is in a certain radius to them.
How is the best way to do this?
This is how I set my markers:
Marker marker1 = googleMap.addMarker(new MarkerOptions()
.position(new LatLng(49.793012, 9.926201))
.title(getString(R.string.Title1))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));
Marker marker2 = googleMap.addMarker(new MarkerOptions()
.position(new LatLng(49.792742, 9.939118))
.title(getString(R.string.Title2))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));
Marker marker3 = googleMap.addMarker(new MarkerOptions()
.position(new LatLng(49.793349, 9.932558))
.title(getString(R.string.Title3))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));
Solution code:
LatLng markerPosition = marker.getPosition();
myLocation = locationManager.getLastKnownLocation(provider);
Location markerLoc = new Location("marker");
markerLoc.setLatitude(markerPosition.latitude);
markerLoc.setLongitude(markerPosition.longitude);
float meters = myLocation.distanceTo(markerLoc);
You can get the LatLng of the markers by marker.getPosition(); then you can compare it with the CurrentLocation. To do this, you can check this post, and next you can make clickable or notclickable a marker as follows:
getMap().setOnMarkerClickListener(new OnMarkerClickListener() {
public boolean onMarkerClick(Marker marker) {
onMapClick(marker.getPosition());
return true;
}
});
If you return true for the function, it means that you've accepted the occurred click event on your marker; otherwise, you've not accepted it.
Moreover, you can do it with:
MarkerOptions.clickable and Marker.setClickable.
This is just a guide who how I would do what you want. hope it helps. :)
I have a Jar with geopoints, I use this bit of code to find the nearest city :
GetNService gn = new GetNService();
NGeoPoint nearest = gn.getN(lat, lon);
GeoPoint city = nearest.getPoint();
I would like to add a marker, but I don't know how to add with Geopoint.
Thanks
You can get the lat and lang values from a GeoPoint like so
GetNService gn = new GetNService();
NGeoPoint nearest = gn.getN(lat, lon);
GeoPoint city = nearest.getPoint();
double lat = city.getLatitude();
double lon = city.getLongitude();
you can add a Marker like so
map.addMarker(new MarkerOptions()
.position(new LatLng(lat, lon))
.title("Marker Title"));
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