Bing Maps REST API Snap to Route Fails Silently - bing-maps

I'm running into an odd problem using the snap to route feature of the Bing Maps REST API. It works great for most of the GPS coordinates I send it -- they were recorded by me on a recent motorcycle trip, so they're "contiguous" -- but fails silently for others.
As in, the returned status code is 200...but rather than returning SnapToRoadReponse objects it returns Route objects. Which lack any of the snapped-to coordinates I need.
What's particularly interesting is the problem occurs in the middle of processing the entire route. In other words, it works fine for 6 or so invocations (each with around 100 points), fails for a number of invocations, and then works fine for the remaining invocations.
Is there a rate limit on how frequently you can access the snap-to service? I'm using just a basic Bing Maps account but could program around rate limitations easily enough (e.g., by waiting beyond invocations). But I couldn't find reference to such in the documentation I reviewed.
Or maybe Bing Maps just doesn't like the hills east of Santa Rosa and the 101 corridor south from there other the Golden Gate Bridge... :)

Turns out the problem was sending too many points through the request pipeline. The Bing Maps REST API requires/strongly advises not to use GET requests involving more than 100 geographic points. I assumed the Bing Maps REST Toolkit took care of ensuring larger requests were done as POSTS. It does not, however, appear to do that.
Reducing the number of geographic points to no more than 100 per request solved the problem.
The portion of my route which was causing problems involved high speed freeway travel, which caused my code to interpolate additional points for each set of observed data points so as to ensure no two points were more than 2.5 kilometers apart (that's a Bing Maps hard limit). That drove the total number of points for each request along that stretch of the route to over 100 points, causing the problem I encountered.

Related

How to get maxspeed from overpass for multilevel intersections/roads?

How can I get speed limit for multilevel intersections/roads? When I go over the bridge or under the bridge, I can get wrong speed limit.
I am using: way[maxspeed](around:20, <latitude>, <longitude>), but I cannot specific altitude.
I am using Overpass API by OpenStreetMaps.
Unfortunately, your current approach of considering speed limits of any road within a certain radius around your location is likely to struggle not just at multilevel intersections, but also with parallel roads and at regular intersections involving ways with different speed limits. It assumes that you know your location with an accuracy that you won't have available in many use cases, and fails in 3 dimensions because OpenStreetMap data does not contain altitude information, only a vertical ordering (i.e. whether an object is above or below another).
It seems to me that the problem you need to solve is finding out which road you're actually on. Once you know the road, you can easily access any of its attributes, including those relevant to speed limits.
This problem of finding the corresponding road for a location, and preferably a history of past locations, is called map matching. For OpenStreetMap data, I believe GraphHopper offers a map matching implementation and API.

Facebook Graph API - Place Distance Inaccurate

I am trying to use Facebook Graph API to retrieve a set of places at a certain coordinate.
Using the API, I executed the following query:
https://graph.facebook.com/search?access_token=APPTOKEN&type=place&center=3.187501,101.627542&distance=50000&limit=500
Theoretically, this query should return 500 places within 50km of that coordinate. However, it only returned some 15 results that are within the immediate vicinity (say few hundred meters) of that coordinate. I tried changing the distance to 10000, 5000 or even 1000, while tweaking the limit parameter to figures such as 50, 100, 1000 but the total results remain the same.
There are certainly other places nearby, i.e. if I change the query's coordinates to the following location which is less than a kilometer away, it returns a whole new result set:
https://graph.facebook.com/search?access_token=APPTOKEN&type=place&center=3.192022,101.625647&distance=50000&limit=500
Can someone please advice if my query is problematic, or that Facebook's Graph API is somehow limiting the distance or total results?
Thank you.
The fact that you only get 15 places in that kind of search was a bug on Facebook.
This bug has been solved today so your query should work better now (I actually tried and it does). Anyway here you can see more details about this bug.
What I personally don't know is this: Now your query returns around 450 results, if you limit it to 5km instead of 50km is still more or less the same amount of places.
I tried queries with different distances and coordinates, seems to me that Facebook limits your total amount of results so you never have more than around 450 places.
Even using pagination (with an offset) I can't manage to get more results (and I know there are more than 500 places within 50km around New York...)
So if you find the answer to this I would be interested ;)
I am encountering a similar problem, I have built a tool to return geo-locale results based upon keyword, city/state (or zip code) and radius up to 30 miles. What used to work flawlessly up until early December 2013 started to return only 15 results in late December. My "educated guess" is that FB is limiting results to prevent people like you and me from turning a profit from this information!!!

Driving time API other than google directions?

I have an application where I should have the driving time between a point A and a set of points. I have the GPS coordinates of all these points.
I tried to do the job using google maps directions api, but the problem is that the program must wait for a minimum of 1 second between two consecutive requests, so if the destination set contains 40 points I should wait 39 seconds before getting all the answers.
This part of the program is critical so 39 seconds will be a very long time.
Is there any other api that I can use for this?
Note that I'm not interested in detailed directions or distance, the total travel time will be enough, I can later use google directions on the best answer to get these details.
Thanks!
There's Walk Score's Travel Time API which seems to offer just that
The Travel Time API rapidly calculates travel times between an origin and a set of destinations. The distance calculator uses ... driving distance ...

Calculation route length

I have a map with about 80 annotations. I would like to do 3 things.
1) From my current location, I would like to know the actual route distance to that position. Not the linear distance.
2) I want to be able to show a list of all the annotations, but for every annotation (having lon/lat) I would like to know the actual route distance from my position to that position.
3) I would like to know the closest annotation to my possition using route distance. Not linear distance.
I think the answer to all these three points will be the same. But please keep in mind that I don't want to create a route, I just want to know the distance to the annotation.
I hope someone can help me.
Best regards,
Paul Peelen
From what I understand of your post, I believe you seek the Haversine formula. Luckily for you, there are a number of Objective-C implementations, though writing your own is trivial once the formula's in front of you.
I originally deleted this because I didn't notice that you didn't want linear distance at first, but I'm bringing it back in case you decide that an approximation is good enough at that particular point of the user interaction.
I think as pointed out before, your query would be extremely heavy for google maps API if you perform exactly what you are saying. Do you need all that information at once ? Maybe first it would be good enough to query just some of the distances based on some heuristic or in the user needs.
To obtain the distances, you could use a Google Maps GDirections object... as pointed out here ( at the bottom of the page there's "Routes and Steps" section, with an advanced example.
"The GDirections object also supports multi-point directions, which can be constructed using the GDirections.loadFromWaypoints() method. This method takes an array of textual input addresses or textual lat/lon points. Each separate waypoint is computed as a separate route and returned in a separate GRoute object, each of which contains a series of GStep objects."
Using the Google Maps API in the iPhone shouldn't be too difficult, and I think your question doesn't cover that, but if you need some basic example, you could look at this question, and scroll to the answer.
Good Luck!
Calculating route distance to about 80 locations is certain to be computationally intensive on Google's part and I can't imagine that you would be able to make those requests to the Google Maps API, were it possible to do so on a mobile device, without being severely limited by either the phone connection or rate limits on the server.
Unfortunately, calculating route distance rather than geometric distance is a very expensive computation involving a lot of data about the area - data you almost certainly don't have. This means, unfortunately, that this isn't something that Core Location or MapKit can help you with.
What problem are you trying to solve, exactly? There may be other heuristics other than route distance you can use to approximate some sort of distance ranking.

Dijkstra algorithm for iPhone

It is possible to easily use the GPS functionality in the iPhone since sdk 3.0, but it is explicitly forbidden to use Google's Maps.
This has two implications, I think:
You will have to provide maps yourself
You will have to calculate the shortest routes yourself.
I know that calculating the shortest route has puzzled mathematicians for ages, but both Tom Tom and Google are doing a great job, so that issue seems to have been solved.
Searching on the 'net, not being a mathematician myself, I came across the Dijkstra Algorithm. Is there anyone of you who has successfully used this algorithm in a Maps-like app in the iPhone?
Would you be willing to share it with me/the community?
Would this be the right approach, or are the other options?
Thank you so much for your consideration.
I do not believe Dijkstra's algorithm would be useful for real-world mapping because, as Tom Leys said (I would comment on his post, but lack the rep to do so), it requires a single starting point. If the starting point changes, everything must be recalculated, and I would imagine this would be quite slow on a device like the iPhone for a significantly large data set.
Dijkstra's algorithm is for finding the shortest path to all nodes (from a single starting node). Game programmers use a directed search such as A*. Where Dijkstra processes the node that is closest to the starting position first, A* processes the one that is estimated to be nearest to the end position
The way this works is that you provide a cheap "estimate" function from any given position to the end point. A good example is how far a bird would fly to get there. A* adds this to the current distance from the start for each node and then chooses the node that seems to be on the shortest path.
The better your estimate, the shorter the time it will take to find a good path. If this time is still too long, you can do a path find on a simple map and then another on a more complex map to find the route between the places you found on the simple map.
Update
After much searching, I have found an article on A* for you to to read
Dijkstra's algorithm is O(m log n) for n nodes and m edges (for a single path) and is efficient enough to be used for network routing. This means that it's efficient enough to be used for a one-off computation.
Briefly, Dijkstra's algorithm works like:
Take the start node
Assign it a depth of zero
Insert it into a priority queue at its depth key
Repeat:
Pop the node with the lowest depth from the priority queue
Record the node that you came from so you can track the path back
Mark the node as having been visited
If this node is the destination:
Break
For each neighbour:
If the node has not previously been visited:
Calculate depth as depth of current node + distance to neighbour
Insert neighbour into the priority queue at the calculated depth.
Return the destination node and list of the nodes through which it was reached.
Contrary to popular belief, Dijkstra's algorithm is not necessarily an all-pairs shortest path calculator, although it can be adapted to do this.
You would have to get a graph of the streets and intersections with the distances between the intersections. If you had this data you could use Dijkstra's algorithm to compute a shortest route.
If you look at technology tomtom calls 'IQ routes', they measure actual speed and travel time per roadstretch per time of day. This makes the arrival time more accurate. So the expected arrival time is more fact-based http://www.tomtom.com/page/iq-routes
Calculating a route using the A* algorithm is plenty fast enough on an iPhone with offline map data. I have experience of doing this commercially. I use the A* algorithm as documented on Wikipedia, and I keep the road network in memory and re-use it; once it's loaded, routing even over a large area like Spain or the western half of Canada is practically instant.
I take data from OpenStreetMap or elswhere and convert it into a directed graph, assuming (which is the right way to do it according to those who know) that any two roads sharing a point with the same ID are joined. I assign weights to different types of roads based on expected speeds, and if a portion of a road is one-way I create only a single arc; two-way roads get two arcs, one in each direction. That's pretty much the whole thing apart from some ad-hoc code to prevent dangerous turns, and implementing routing restrictions.
This was discussed earlier here: What algorithms compute directions from point a to point b on a map?
Have a look at CloudMade. They offer a free service for iPhone and iPad that allows navigation based on your current location. It is built on open street maps and has some nifty features like making your own mapstyle. It is a little slow from time to time but its totally free.