Getting coordinates of polygon areas defined in KML - google-maps

I have displayed a google map using a KML file as source. The map has a number of polygon areas marked in it. Is there any way to get the center coordinates of each of the polygons without the click event ? I need to display an info window above each polygons when the map is displayed.
Thanks

google.maps.KmlLayer is uses tile based rendering, you can't (at least at present) access the coordinates of the polygons except on a click.
You could use:
FusionTablesLayer, import your KML into that, then query it using either a Fusion Tables API v1.0 or a google.visualization (GViz) query) for the coordinates to get their center.
example using FusionTablesLayer and GViz
A third party KML parser like geoxml3 or geoxml-v3 to render the polygons as native google.maps.Polygon objects, and get their center. This will have performance issues with complex KML.
example using geoxml3

Related

Create custom map overlay (polylines) [Mapbox]

I have a Flutter project using flutter_map and tiles from Mapbox. I also have a very large list of coordinates to create polylines on the map. The coordinates are worldwide geographical boundaries. It's working fine but when displaying the polylines the map gets a bit unresponsive due to the amount of polyline data.
How would I be able to create a custom map with the coordinates/polyline data already embedded in the map to avoid having to draw polylines separately?
Thanks
You could use Mapbox Studio to create a map style with sources and layers referencing these coordinates/polyline data. This tutorial on creating a custom style is a great place to get started.

Loading kml markers above polygon

I am working with a google map api 3, on my map i want to generate kml markers after polygons, but it is not working, my markers are generate before polygons so i am not able to click marker.
Native Google Maps Javascript API v3 polygons will always appear on top of KML layers. If you want to control the order, use a KmlLayer to display the polygon as well, add that layer first or control the order with the zIndex property of the KmlLayers.
related question: https://stackoverflow.com/questions/35455830/kml-ordering-in-google-maps-api (including example)

Is it possible to add a Polygon layer to a google map v3 without using fusion tables

The question is pretty descriptive.
I am working on a website that provides locations for filming.
All the data in the site is currently stored in a MySQL database including geocode data for google maps.
I need to show polygon areas for the different london boroughs that has locations.
I have all the data as kml files, idealy i would like to store this in the MySQL database.
I have had success using fusion tables to display this data, but it seems silly to me to have to have this data duplicated on google just to use a fusion map layer, can i simply use a kml layer to render this data rather than having to create a fusion table and rendering it from that?
If so, is there a resource someone could point me to for more information?
UPDATE:
Thank you for the responses so far, i thought i would update the question with a little more info .
I eventually want to have all the areas displayed at the same time on my map and then when an area is clicked on ideally it would take you to another page on the website showing locations for that specific area.
I had initially tried using KML layers but i was getting errors saying my KML was invalid.
The KML was initially stored in a field in my database table, i think probably the errors were due to me not understanding exactly how google read in the KML data.
Using polygons would be far simpler to implement as i can get this data via JSON and then render the polygons from that.
I know now its not possible to have info windows with polygons, but i would just prefer to jump directly to another website page with info for that particular area using a click handler rather than show an info window.
Alternatively as suggested showing a tool-tip with a brief description of the area and a link to the page would be better, how the tooltip itself, is it possible to render on top the map?
I am slightly worried that I will reach the layer limit for the KML.
Is it possible to have multiple polygons rendered with KML on one layer, or do i need a separate layer for each clickable area?
The Google Maps API provides a pretty straightforward method to draw polygons.
Basic Example:
var polygon = new google.maps.Polygon({
map: your_google_map_instance,
paths: array_of_latlng_points,
fillColor: "#336699",
fillOpacity: .5,
})
EDIT: For this approach, you would need to parse your KML files (sorry, must've missed that when I first read it). You can import the KML files to a KML layer
You can overlay Polygons using KmlLayer, FusionTablesLayer (as you know), or native google.maps.Polygon objects.
KmlLayer and FusionTablesLayer render them as tiles, so for lots of Polygons (if you only need click events) will be more efficient. There are limitations on the number of KmlLayers that can be displayed on the map at one time and on FusionTablesLayer (but those don't seem to be causing you problems).
There are also third party parsers available for KML (geoxml3, geoxml-v3) which will take your KML and render it as native google.maps.Polygon objects. For lots of Polygons, this will be less efficient than tile based rendering, but it does allow mouseover/mouseout, and changing the properties of the Polygons dynamically.
You could also try data layers what have lots of events so you can display tooltips, info window, status text on various mouse events.
See samples in documentation:
https://developers.google.com/maps/documentation/javascript/datalayer
If you have many polygons (where the actual value of many depends on multiple factors, can be anywhere between 100 and 1,000) the best is to use a built in layer type. The fastest are the ones rendered on server, e.g. kml layer because this doesn't create hundreds of DOM elements in browser but still exposes click events so infoboxes can be displayed for each item.
In the worst case you can implement your own rendering with an image map, obviously by using an existing library like mapnik.
https://developers.google.com/maps/documentation/javascript/maptypes#ImageMapTypes

Can I manipulate a KML using Google Maps API v3?

I'm loading a KML using KMLLayer in Google Maps API v3. Is it possible to reference the polygons on the map and do things like change color or transparency?
No you can't do it like that since there are no polygons like objects in a kmllayer. From the google docs:
The Maps API converts the provided geographic XML data into a KML
representation which is displayed on the map using a V3 tile overlay.
This KML looks (and somewhat behaves) like familiar V3 overlay
elements. KML and GeoRSS point elements are rendered as
markers, for example, elements are rendered as polylines
and elements are rendered as polygons. Similarly,
elements are rendered as rectangular images on the
map. Importantly, however, these objects are not Google Maps API
Markers, Polylines, Polygons or GroundOverlays; instead, they are
rendered into a single object on the map.
This page might be helpfull in exploring alternatives

Google Maps - Online Map Marker to mark polygons and shapes onto the map

I'm looking looking for a tool that will allow me to make a map exactly like this:
http://datasearch.uts.edu.au/about/mapsdirections/map.cfm
Basically I need to put shapes around buildings in the satellite view and then slap a marker and information window on them so that I can specify the building name and contents.
So the main issue is that I need the ability to draw shapes directly onto the maps as I don't fancy taking down the lat lng of each corner of the polygon.
Ideally what I'd like to do is have an online application that exports those points to KML, and then I would display google maps on my site and import that kml to display it.
Other suggestions welcome!
Jason
Found a polygon creator
http://www.the-di-lab.com/polygon/
It's simple to use and allows you to copy and paste straight into your code. Would be nice if it had a button that said sent to kml though..