Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps: How can I change the z-index of a Marker?

There are about 100 markers on a google map plus there is one special marker that needs to be visible. Currently, the markers around it hide it totally or partially when the map is zoomed out. I need that marker to be fully visible and I think keeping it on top of all other markers should do the trick. But I cannot find a way to modify its stacking order (z-index).

like image 439
Salman A Avatar asked Mar 06 '10 09:03

Salman A


People also ask

How do you customize a marker in maps?

For adding a custom marker to Google Maps navigate to the app > res > drawable > Right-Click on it > New > Vector Assets and select the icon which we have to show on your Map. You can change the color according to our requirements. After creating this icon now we will move towards adding this marker to our Map.

How do I reset a marker on Google Maps?

You remove markers by using set_map(null) on the particular marker you want to clear, if you want to clear all then loop through using this function.

What is Z in Google Maps?

Use the geo: intent to display a map at a specified location and zoom level. latitude and longitude set the center point of the map. z optionally sets the initial zoom level of the map.


2 Answers

This is for Google Maps API 2.

For Google Maps API 3 use the setZIndex(zIndex:number) of the marker.

See: http://code.google.com/apis/maps/documentation/javascript/reference.html#Marker

like image 124
jhanifen Avatar answered Oct 02 '22 22:10

jhanifen


Use the zIndexProcess option in GMarkerOptions when you create the marker that you want on top. For example:

var pt = new GLatLng(42.2659, -83.74861);
var marker = new GMarker(pt, {zIndexProcess: function() { return 9999; }});
map.addOverlay(marker);

I believe the default is to have a z-index that is the latitude of the point of the marker, so this should be fairly safe at bringing a single marker to the front. Further, this was just a simple example; you can set the z-index of all your markers in whatever simple or complex way you want. Another example is to have two functions: one for special markers and one for the rest.

var pt1 = new GLatLng(42.2659, -83.74861);
var pt2 = new GLatLng(42.3000, -83.74000);
var marker1 = new GMarker(pt1, {zIndexProcess: specialMarker});
var marker2 = new GMarker(pt2, {zIndexProcess: normalMarker});
map.addOverlay(marker1);
map.addOverlay(marker2);

function specialMarker() {
  return 9999;
}

function normalMarker() {
  return Math.floor(Math.random()*1000);
}
like image 25
Mark Avatar answered Oct 02 '22 21:10

Mark