Add text overlay to Google Maps

This is such a simple problem, but I can not find the answer anywhere ...

I have a python script that returns a bunch of numbers that represent the total number of elements for a given geographic region. I have a bunch of .kml files I made that represent geographic boundaries for each region. I want to take these numbers created using a script and paste them on top of the top .kml overlay. I can’t figure out how to do this. I know how to add .kml files, but I cannot figure out how to do this. Theres a lot of information on google on how to add marker icons, polylines, even images to a map, but I can't find how to add just a simple bit of text.

+4
source share
2 answers

There are several third-party extensions to help you easily accomplish this. Try ELabel . It works as follows:

 var label = new ELabel(new GLatLng(44.3,-78.8), "Utopia", "style1"); map.addOverlay(label); 
+3
source

You can translate from latitude, longitude to the pixel offset inside the map div using the fromLatLngToDivPixel method of the GMap2 object.

To show the div at this pixel offset, you need to attach it to the corresponding div. In fact, a map consists of multi-layered sections called panels. You can access the div for a particular panel using the GMap2.getPane method . You can try inserting your div on any of the panels described in the GMapPane enum.

So, we summarize:

  • Attach your absolutely positioned text div (display: none) to the corresponding panel separator.
  • Take your latitude and longitude and translate it to the pixel offset of the div div.
  • Set the top and left attributes of your absolutely positioned text div and display it.
+4
source

All Articles