Does a polygon loaded from a KML contain a given Lat/Lng in Google Maps API - google-maps-api-3

I have a KML file which contains a polygon. I am wanting to write a simple application which will give a true/false result on whether a lat/lng is inside of that polygon.
For whatever reason, this seems to be more difficult that it sounds, as the google.maps.KmlLayer seems to be very limited with the functions it offers.
I am aware that a non-KML map has a "containsLocation()" function which does exactly what I need, however, the KML layer contains no such function

I am not quite sure how you are using the KML file however I would suggest the following approach:
Parse your KML file (Many libraries available for many languages)
Use the parsed KML data to render your Polygon using the Google Maps API (i.e. reconstruct you KML polygon in Google Maps with the Google Maps methods)
Use the Google Maps API containslocation() method to check whether a co-ordinate is inside the Polygon
The Google Maps API has a large feature set so by doing this you could incorporate some of their methods, i.e. You click on the map and the program tells you wether the point you have just clicked is inside the polygon or not. Have a look at this, I suspect this is what you want to accomplish (or at least similar to it).
Edit: By parse I mean decode the KML

Related

Acquire and reconstruct map from online interactive maps

I am scraping data from some interactive maps, including markers locations, and would like to acquire and reconstruct the map image to use with those markers. For example, consider the map for the videogame Elden Ring provided by Map Genie here.
From what I understand, the tiles are 256x256 and are fetched depending on the user's view position and their zoom.
I am unaware how I may programmatically acquire all the map tiles (and put them together) such that it still relates to the longitude/latitude data of the scraped markers. I generally use Selenium in python to scrape web data, but in this instance, the data is 'dynamically fetched', and I'm not sure how to start.

Drawing HERE Data on to ESRI JS Map

I am currently investigating the possibility of utilising the HERE APIs as source data inputs into possible solutions we would like to develop as a company on ESRI.
I understand that any data we retrieve from the API, i would need to create ESRI objects on the fly, and add them to an ESRI map layer.
However, one thing that is not clear in my mind, is how to calculate the tiles for my particular map extent.
The REST API specifies some base information, regarding calculating tiles based on lat lon - but what is the lat/lon of? is the map center? is it the bottom left or bottom right?
Are there any JS helper methods that HERE have, that would calculate the tiles required for a particular extent?
Are you referring to this documentation part: https://developer.here.com/documentation/map-tile/common/map_tile/topics/mercator-projection.html ?
It is the coordinate of the part of the map which you want to display e.g. the center of your map view.

what is the MapBox solution to add a vector-tile layer into Leaflet map?

Background:
Leaflet map
a vector tile layer
MapBox Studio to generate vector tiles (protocol buffer format)
MapBox.com for tile hosting
using Leaflet.MapboxVectorTile plugin to parse and render MapBox vector tiles
Issues:
Cannot get original feature geometry: I wanted to fetch feature geometry so can zoom to it e.g. when user clicks at it. But this plugin (Leaflet.MapboxVectorTile) doesn't have a clear way to do so. The geom values (including BBOX) are all in relative coordinates (i.e., not the original geometry)
Poor capability in identifying feature (click/hover): Another problem with this plugin is its identification algorithm is not robust enough. The authors disabled hover-identify as it turns out to be very slow. For clicking, I noticed sometimes it's hard to select a polygon (happens for some polygons and depends on where you clicked within the polygon), you have to click at certain locations so the plugin is able to identify the feature.
This plugin is very good in my experience except for above two issues.
My Questions:
Is there a counterpart MapBox solution that does the similar thing to this plugin? In other words, to parse and render a vector tile layer service on map, with support in robust feature identifying and ability to fetch feature geometry?
Currently the tiles generated in MapBox studio is in .pbf which is great in terms of efficient data transmission. I wonder if it supports JSON format (GeoJSON or TopoJSON) out of box? If it does, I probably could try using MapBox.JS featureLayer to consume vector tile json data.
I understand MapBOX GL.js is designed for vector tile based maps. I am looking for adding a vector tile layer though.
appreciate any response. thanks!
You'll want to try out mapbox-gl-leaflet, a library that integrates the efficient Mapbox GL library into Leaflet as a layer.
Cannot get original feature geometry
Vector tiles do not contain the original feature geometry. Mapbox GL does provide an api that delivers GeoJSON, but it isn't going to be your raw data: if it was, then the map would be slow and inefficient, since raw data is over-detailed.

api for retrieving object at a specific gps coordinate

I have been reading the google maps api and the openstreetmap api, but i cannot find if they offer the following functionality:
I need to find out if at a specific gps coordinate there is a building or a street.
Do you know of any api offering this?
Thanks.
I wonder how you could missed that if you already did look at the documentation.
Of course OpenStreetMap can do this. There is the main API (which is primarily for editing and not for bulk querying!) where you can retrieve all map data within a specified bounding box.
Example:
http://api.openstreetmap.org/api/0.6/map?bbox=13.76500,51.05600,13.76515,51.05615
This will return all objects between latitude 51.05600 and 51.05615 and longitude 13.76500 and 13.76515. For how to interpret the returned XML file read OSM XML in the OSM wiki.
In order to know if a specific object is a building, a street or something else you have to look at the tags. Buildings are usually tagged using the building key and can either be a single node, a way or (rarely) a relation. Streets are usually ways and are tagged using the highway key.

Google Maps - How do I efficiently create a polygon with many points?

I need a polygon for every German state. I go all the GeoPoints in one JavaScript-file but the file is because of the amout of points about 4MB. I've been googling and thinking about this problem all day but couldn't figure out a solution...
How can I use Google Maps polygons without forcing the user to download a huge js-file with the coordinates?
Thanks!
Ron
You can encode the polygon points to vastly reduce the size of the javascript file. To do this, you must include the geometry library.
https://developers.google.com/maps/documentation/javascript/reference#encoding
https://developers.google.com/maps/documentation/javascript/geometry#Encoding
One option is to use a FusionTablesLayer to display the polygons. They are available in the Natural Earth data set that is publicly available.
Example
You could do the same with your points and a KmlLayer if you convert your data to KML.
Well... somehow the points have to get to the user. You could think of the following solutions to reduce the data usage:
Use different polygons for different zoom levels. For example zoomed out you won't need the full details.
only send parts of your polygon back to the user. You can for example send the viewport coordinates to an AJAX script. This one queries your database and/or shapefile and only returns the polygon parts that are visible in the user's viewport
preprocess tiles. If you can generate images from your shape, you can overlay these on Google Maps.

Resources