Display my location marker above all others - android

I am using google maps in my android app, and I wanted to use a custom myLocation marker
I need it to be on top of the other markers, how can make it be on top ?

Try below code, it helped me to show marker above to all other markers
mMap.addMarker(new MarkerOptions()
.position(mLatLng)
.title("" + name)
.snippet("" + pingDate)
.icon(BitmapDescriptorFactory.fromBitmap(icon))
.zIndex(yourZIndex));
Here is screenshot of my application

Related

Move the marker along the with map as the user moves

I have implemented google map into my app. I have added a custom marker at my current location.I want to move the marker as the user moves, along with the map. I want to implement the functionality as in google maps navigation. While googling i found the following links but did not get the result. so can any one help me out ?
I have added this in onLocationChanged()
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
sourceLocation = latLng;
startPoint = new GeoPoint(latLng.latitude,latLng.longitude);
forNavigation = location;
// animation
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
mMap.animateCamera(CameraUpdateFactory.zoomTo(15));
// mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mPositionMarker.getPosition(), 15));
mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(location
.getLatitude(), location.getLongitude())));
These are the links which i found
Google map: moving marker and map together smoothly along with user?
How to smoothly keep moving current location marker in Google Maps v2 android
here is two solution you have.
Use onlocationtrue then it show you blue dot as your current location.
Use fused api for current location and create you marker in locationchanged.
for fused api you can check from here.
thanks

Using a text file to insert multiple Markers on the Google Maps V2

In my recent post i was asking for the way to insert multiple Markers on the google map via an ArrayList.
Now i want to use a text file to store (position , title , snippet , icon)
Assuming that i use this code to store every marker:
Marker marker1 = map.addMarker(new MarkerOptions()
.position(new LatLng(1.123456, -2.123456))
.title("Title1")
.snippet("Snippet1")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.icon1)));
Marker marker2 = map.addMarker(new MarkerOptions()
.position(new LatLng(3.123456,-4.123456))
.title("Title2")
.snippet("Snippet2")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.icon2)));
...
How to use a text file to store all marker properties and how to use these properties in my map ?

Android Google Map multiple markers on same location

I have a simple app with Google Map and dynamicly loading markers. In case 2 or more markers have same lat and long only one is presented. Is there any solution for this? This is how I plot markers to map
private void plotMarkers(ArrayList<MyMarker> markers, String markerIcon)
{
if(markers.size() > 0)
{
for (MyMarker myMarker : markers)
{
// Create user marker with custom icon and other options
// Toast.makeText(getApplicationContext(), myMarker.getmLatitude().toString(), Toast.LENGTH_SHORT).show();
MarkerOptions markerOption = new MarkerOptions().position(new LatLng(myMarker.getmLatitude(), myMarker.getmLongitude()));
markerOption.icon(BitmapDescriptorFactory.fromResource(manageMarkerIcon(markerIcon)));
Marker currentMarker = mMap.addMarker(markerOption);
mMarkersHashMap.put(currentMarker, myMarker);
mMap.setInfoWindowAdapter(new MarkerInfoWindowAdapter());
}
}
}
Even if you could, how would you use these two overlapping markers? only the top one would be visible.
Instead, if two markers overlap, you could express the data they share in one marker that contains them both.
this answer might assist: Android Google Maps v2 - Add object to marker
Both markers are shown, but both on the same location and it seems to be only one, and if you click on them, only one info window will be presented.
If you really need to add two markers at the same location you may want to take a look at Google Maps Android Marker Clustering Utility. It's part of the Google Maps Android API Utility Library.
A possible workaround could be to check if there is another marker in the position you are trying to draw the marker into, and if so, move the new marker a little bit appart.

How to add a marker on Google map v2 using overlay?

i am working on a project, where i have to add a marker using overlay to existing Google map.
i have multiple markers along with infoWindowAdapter,for these i must pass title and snippet. I need one more marker to show only title(i can't directly add a marker with only title,since i used infoWindow for markers it will asks for snippet and ended up with null pointer exception)
I tried this
LatLng currenLoc = new LatLng(location.getLatitude(), location.getLongitude());
Toast.makeText(getApplicationContext(), ""+currenLoc, Toast.LENGTH_SHORT).show();
GroundOverlayOptions curLoc = new GroundOverlayOptions().image(BitmapDescriptorFactory.fromResource(R.drawable.mrk1)).position(currenLoc, 350f, 350f);
gMap.addGroundOverlay(curLoc);
but it shows only a marker like picture not an exact marker. So how to add a marker using ground overlay.?

Marker changes its position while zoom in or out in google map v2 in android

I am using Google map V2 to put several markers on map. i am using default marker with different color, my problem is that when i perform zoom in or out operation marker changes its position.
I have searched a lot but didn't get any solution.
to add marker i am using following code
myMap.addMarker(new MarkerOptions().position(new LatLng(serverResponse.get(i).getLat(), serverResponse.get(i).getLon())).title(data).snippet(data2));
You have forgotten to call to the method
.anchor(float a, float b)
when you are adding your maker.
Please try this:
myMap.addMarker(new MarkerOptions().position(new LatLng(serverResponse.get(i).getLat(), serverResponse.get(i).getLon())).title(data).anchor(0.5f, 0.5f).snippet(data2));

Categories

Resources