Plotting routes with here.com api - here-api

I'm using the Here.com "maptile" api to populate my map with map tiles. Now I want to add routes from point A to B to the map. I figured Here's routing api would provide me with a nice set of coordinates to use for plotting a line in the map, but the api only provides one coordinate pair per "maneuver" (that is, at roundabouts, exits, intersections etc). That is not detailed enough to use for plotting routes since all roads are not perfectly straight ;)
Example
This example at Here's api playground shows a red route plotted perfectly along a road using their map image api. However, if you run the start and end coordinates in the "m1" field through the routing api, you will get the following coordinates:
52.5408395,13.2626364,52.5403011,13.2630944,52.5289285,13.2687593,52.51873,13.2800306
If you enter these coordinates in the "r1" field and click Send Request, you will see that the route is plotted differently (straight line across the park, instead of along the yellow road).
Question
Is there any way to get more detailed data from Here.com's routing api (or any other Here api I may have overlooked), suitable for plotting roads?
Or is there perhaps some way to get map tiles from the maptile api with a route properly pre-rendered?

In HERE Routing API, you can ask for route shape with parameter &routeattributes=shape
This will return an array of coordinates which represents the exact shape of the route on the road. You can also use pedestrian mode which will take into account the roads only accessible on foot.
Unfortunately it's not possible to get map tiles with rendered route shape using Map Tiles API. This API is just for fetching tiles.

Related

Drag route anywhere using Maps API

I want to write an application that gives me the exact route of a subway.
When you use Google Maps it just connects two stops linearly, but not the actual way.
Is there a way to move a route anywhere on a map without being bound to roads?
If there's any solution (doesn't have to be with the Google Maps API) please let me know.
Edit:
Example
Google shows the train route like the brown line, but the train actually drives the blue line. What I would like to do is get the blue line so that I can get the coordinates of the route and calculate the curves and elevation.
I know that I could add like 50 waypoint and get get a "fake" route with them, but I would like to have it automatic and not done by hand.
To show the transit directions (subway, bus, tram, etc.) Google Maps uses the data provided by transit agencies in the form of GTFS feeds. This is a responsibility of the agency to provide a detailed shape of the route for the transport according to the GTFS specification. You can have a look at GTFS documentation to figure out how does it work:
https://developers.google.com/transit/gtfs/
https://developers.google.com/transit/gtfs/reference/#general_transit_feed_specification_reference
I hope this helps.

Google Maps - Follow Path Of Travel

I am working with a security company that has a patrol car travel around a neighborhood. Every 30 seconds, they record a GPS coordinate/point which I can download and use. I'm trying to map a 'path of travel' for the patrol vehicle using Google Maps API.
I understand how to map (marker) all the points using the Google Maps v3 API. I also understand how I can do a driving route between a few points using directionsService. According to Google and StackOverflow, the maximum number of waypoints is 26.
The problem is that I have dozens of these points (1 hour = 120 points). I can't just draw a polyline between the points because I need it to show the path of travel on the actual street - not as the crow flies between 2 points. Also, I don't have 10K to purchase an Enterprise license.
Any ideas on how this might be accomplished or am I SOL? Can you draw 120 multiple 'routes' on the same map? Speed is not important here.
Thanks,
Mike
Can you draw 120 multiple 'routes' on the same map?
You can. When you want to draw the routes by using the DirectionsRenderer you must use a separate DirectionsRenderer-instance for each route.
Another approach: request the routes via the DirectionsService, but use a custom Polyline to draw the route. Each time you get a new route you'll only have to push the points of the new route to the path of the polyline.

Nokia Map Tiles REST API

I have an account for Nokia Maps API but am wondering what URL I should use to request tiles through the API correctly? I am using the Leaflet maps API and my URL string looks like this:
http://3.maptile.lbs.ovi.com/maptiler/v2/maptile/newest/normal.day/{z}/{x}/{y}/256/png8?app_id=XXX&token=XXX
It works, but I don't believe I am using the API correctly - I just stole the first part of the URL (http://3.maptile.lbs.ovi.com/maptiler/v2/maptile/newest/normal.day) from the Network tab of dev tools when I checked out Nokia maps in my browser.
In the documentation it tells me I can request based on lat, long and zoom, but not based on X and Y.
Is anybody familiar with Nokia Maps API?
Regarding the original question I'm guessing you have acquired credentials for the Map Image API: http://developer.here.net/docs/map_image/index.html There are a series of interactive examples available, which explain how to get back a static map image using latitude and longitude such as this one here: http://developer.here.net/apiexplorer/examples/api-for-rest/getting-started/basic-map-wh.html All the urls for the Map image API start with http://m.nok.it
Using URLs for the map tiles from the http://here.com website isn't the same service, it isn't an official API (hence the reason it is undocumented) and the URLs could be changed without notice.
Updated
HERE now offers three web-based Maps APIs, and since last year a TMS (Tile Map Service) a.k.a. Map Tile API, which is what I think you are after is now publicly available.
As noted by Luciano Issoe, the correct URLs for the Map Tile API are now publically documented see: https://developer.here.com/rest-apis/documentation/enterprise-map-tile
Alternatively, if you want to use an interactive map service with Nokia's mapping data, your best bet would be to use the Maps API for Javascript described here:
http://developer.here.net/docs/maps_js/index.html
It seems that it´s a documented service now: https://developer.here.com/rest-apis/documentation/enterprise-map-tile
To retrieve a map covering a specific area using the Map Image API, add two points of interest to the map for the top right and bottom left corner and then use the nomrk to make the POIs invisible:
http://m.nok.it/?w=512&poi=52.6764,13.7636,52.351,13.0185&nomrk

Create directions on a map based on custom data

So what I'm trying to do is the following:
Have a map (such as Google Maps or questMaps). It doesn't matter at all which API I need to use.
On that map have an overlay on the streets. So say (for example) the street has bad lightning at night, it will be colored red. If it has good lightning it will have a green overlay.
Based on the overlay the map creates a custom route (for example the user only wants to walk on the green/well lit streets).
I have no idea how to accomplish this (especially step 3).
First, you'll have to decide what data you need. How do you categorize certain streets as lit or unlit? What if some parts of a street are well lit and some have no lights? Do you need to know the location of every streetlight in your area? What if lights burn out?
After figuring out what data you need, you need to build your dataset. I'd be VERY surprised if this data already exists, so you will probably need to gather it yourself. Either go around town and take notes, or crowdsource the project, or figure out some other way.
Once you have gathered your data, learn the drawing API of whatever mapping tool you wish to use. They all should have functions in their API for drawing colored lines (for streets) or points (for streetlights) on top of an existing map.
Finally, learn the navigational API of the mapping tool you chose. You're right, this is a hard step. I know Google Maps lets you specify certain waypoints when requesting directions; maybe your app can calculate well-lit waypoints and feed them to Google Maps' Directions service to influence the route it generates.
Good luck!
For custom routing, you need to read up on "Graph Theory". This ignores the geography of the street map, and considers it as a set of junctions (nodes or vertices in the graph theory jargon) connected by edges. You can assign weights to edges - these could be lengths, travel times, ones and zeroes etc. Anything. They can have no relation to the position on the map.
So for your application, you'd assign a large weight to unlit streets, and a small weight to lit streets, then use a standard minimum-weight algorithm to get a route from one node to another.

Finding streets (get their coordinates) and calculating distances between markers

I have trouble finding any information on how to use the API to:
Search for streets and get some clickable results that returns a LatLng object or something (at least coordinates). So If I search for a street and click on a result, I'll pan to that street (for example).
How can I calculate distance between markers? and possibly, draw lines between them.
All I get is the API but no guides so it's fairly hard figuring out what types to use.
Here is a fiddle showing how this can be achieved:
http://jsfiddle.net/foxwisp/vQGMr/1/
To convert street names to lat/lng you need to use a Geocoder such as the one provided by Google Maps API.
Then, when you get back the results from the geocode, you use the lat lng properties to create a marker. Once your first marker is placed, you repeat the process for your second street address. We nest these calls so that we can be assured of the order of execution due to their asynchronous nature.
Once we have our second marker we use Google's polyline function to draw a line between the two latlng marker points.
Then we use a slightly complicated mathematical equation to do some distance calculations and voila.
The Google Maps API is fantastically documented, hopefully this fiddle will put it into context for you and you can explore each element step by step by reviewing functions and properties in the documentation

Resources