I am looking for examlpes of how to use polylines in V3 of Google maps, I have read the help at Google but must admit I don't fully understand. I feel if I could see a good example I might understand it better. What I have is a site that I track my vehicle I have it plotting the points on the map what I want is to draw the line between the points. I am using a mysql database and a XML file with PHP to display the point on the map.
Any help would make my day. I have found this site very helpful and I wish to thank all.
Take care, all the best
It's a matter of creating a KML xml file, using data from your database, and feed google api with that. You can use this tool to interactively see how the kml file changes while adding points to the polyline.
EDIT:
Create a script in your preferred scripting language which retrieves the points from database, and generates a kml file format as in the third link above.
In your javascript script, you need to add a kml layer to the map, loading the kml you generate on the fly in your script at point 1. :
[...]
var map = new google.maps.Map(document.getElementById('map'), options);
[...]
kmlFiles = new google.maps.KmlLayer("http://yourdomain.com/generatekml.php");
kmlFiles.setMap(map);
and that's it.
Related
I would like to create an commercial Android GPS app that allows to route a way depending on a speed limit and a vehicle restrictions such us its height and width. I picked GraphHooper as a routing engine and because it does not provide informations about the vehicle's size, I want to add some of the Truck QA Map tags (http://maxheight.bplaced.net/overpass/map.html) and apply it to the GraphHooper's algorithm.
The problem is that GraphHooper is written in Java and from what I see on the GitHub (https://github.com/mmd-osm/osm-maxheight-map), QA Map is based on javascript, php and css.
My question is, is it possible to apply javascript, php and css code to the android project? At this moment I'm considering different solutions and I wonder if it could be done in general. If yes, how it can be done?
There seems to be a misunderstanding.
GraphHopper is a routing engine which is able to process OSM data. Likewise the OSM Truck QA Map is just using OSM data, too (especially the maxheight tag, the OSM wiki has more information about this map).
If GraphHopper doesn't support the maxheight tag yet then all you have to do is add it to GraphHopper. There is absolutely no need to extract it from the QA map because it is already contained in the data used by GraphHopper. You just need to tell GraphHopper to additionally check this tag when calculating its route the same way it already checks lots of other routing tags (like maxspeed, access and so on).
The main purpose of the OSM Truck QA Map is to help you spot any missing maxheight tags in the OpenStreetMap data or visualize already existing tags for trucks, such as maxheight, maxweight, etc. All the data comes in fact from the fabulous Overpass API, so there's not much point trying to extract the data form OSM Truck QA Map. It is really just a visualization tool and works completely in your browser.
Assuming you already have a OSM planet or some smaller extract available for testing, all those maxheight, maxweight, ... tags already exist in that data. You just need to include them in GraphHopper processing (see Scai's reply).
... and if some of the routing results look odd, you might want to check back on OSM Truck QA Map what the actual tagging looks like in the OSM data - or even check what it looked like some time back in the past.
I'm trying to decide if I want to use json or kml to store polygons in a file on a server. I have to read in this file and check which polygon a given point is within. I am attracted to kml because I can render an entire kml file in two lines with the Google Maps Javascript API :
var importedKml = new google.maps.KmlLayer('mykml.kml');
importedKml.setMap(map);
However, I can't find a built-in function for checking if a point is inside all the polygons in a kml file. I know I can check to see if a point is in a polygon using the code below:
google.maps.geometry.poly.containsLocation(latlngPoint, polygon);
but it looks as though I'd have to parse the kml and turn every
<Placemark><Polygon>
feature into a google.maps.polygon object first.
I've thought about going back to json, since json objects are extremely customizable and I could directly call something like
//json object polygonFile from server
google.maps.geometry.poly.containsLocation(latlngPoint, polygonFile.polygons[0].polygon);
with a structure I have built myself. There's no quick and easy way to render json to the map without first converting it to google maps objects and then rendeing those, though, it appears.
Is there a way to check if a point is within a polygon in a kml file without converting each feature to google maps objects first? If not, converting a json object to google maps objects sounds like the way to go.
what about GEarthExtensions . There is a function "containsPoint" for an Polygon object
here is an example:
http://code.google.com/p/earth-api-utility-library/source/browse/trunk/extensions/examples/point-in-poly.html
I have readed the API for elevation for Google Maps and what I can understands I must have the map visible to get the elevation for a point (coordinates). But almost nothing is impossible with JavaScript so I wonder now, is it possible to get the elevation from a point without viewing the map?
Thanks in advance.
Do you know what the co-ordinates are for the point? If so, the API for elevation will return the elevation, in both JSON and XML formats. I use the following URL (albeit in PHP, it should work the same for Javascript):
http://maps.googleapis.com/maps/api/elevation/xml?sensor=false&locations=1.111,1.111.
You'll need to parse the results in JS. Switch XML out for JSON in the URL to change the result type.
Edit: If you use this service, you need to use it in conjunction with a Google Map as per their terms and conditions.
I am working now on little project.
In one view i am returning data for google maps API (longitudes and latitudes).
Under the map I have to implement few buttons to add point of interests on the map in this location which is actually showed.
There could be some buttons/types of POI like schools, banks, atms etc.
So, let's go back. When I put all my markers on map how to add there points of interests?
I would like to get below data for them:
longitude (needed for show)
latitude
type
title
description
I know, that there is google local ajax search api, but I am not sure if it is correct way to do.
I know how to find this data using google maps interface, for example:
Example Map
http://maps.google.pl/maps?f=q&source=s_q&hl=pl&geocode=&q=category:%22Banks+%26+Financial+Institutions%22&sll=51.510202,-0.12144&sspn=0.01859,0.05549&ie=UTF8&cd=1&ei=N4hUS7ynEc7AjAeWtNm4CA&radius=1.19&rq=1&ev=zi&hq=category:%22Banks+%26+Financial+Institutions%22&hnear=&z=15
but how to do this using API?
Thanks.
The Google Local Search API can be used to obtain a small number of such points at a time, as in this example. Or you could just add the Googlebar to your Maps AVI v2 map.
Access to large numbers of such points at once is not available from Google, and is generally not available for free.
In addition to Google, there are other data providers you can use. For example, the API at http://compass.webservius.com allows you to retrieve data on more than 16 million businesses in the US (including name, lat/long, business type / industry code, etc).
The Google API is a Javascript API.
If I understand you correctly, you want to add markers on a Google Map using the Google Maps API.
The documentation suggests that either you hardcode your Markers or create one by creating a Marker Manager.
I have never used Google Maps API but if you want more info, visit the documentation here.
Good luck!
I'm trying to do some network analysis for a client. The provided road-network GIS layer is of bad quality; therefore, I have to resort to Google maps to provide me shortest path between 200 points, to produce time and distance matrices between each point.
is there a way i can input the layer as a set of KML points to obtain outputs of the distance and time between these points ?
if this is doable via the api, do you have any hints or suggestions on how to write such a script?
EDIT
the ideal final result would be a CSV file of the following form:
node_1, node_2, distance, travel_time
node_n, node_m, distance, travel_time
I won't write the whole script for you, but this can be done with the maps API. Open up the maps sandbox and add to the onGDirectionsLoad function:
alert(gdir.getDistance().meters);
You can find the documentation here - a getDuration() is also available. Then all you need to do is issue a new request once one finished, getting directions for each pair of start and end point.
However, note that if you're planning on getting 200*200 paths, google may decide to rate limit you at some point. Use this method at your own risk, and with a delay between requests.
Note also that google's builtin KML support doesn't seem to support giving you the list of points - this makes sense, since the client may only have those that are currently onscreen. You might need to write your own KML loader if you want to use KML as the input format. Or use a simpler format, as in this example.