How to calculate the driving distance between two points? - windows-phone-7

In my app I am getting the latitude , longitude co-ordinates of places using GeocodeService now I want to get distance between these places.
I've tried GetDistanceTo method to get the distance two location co-ordinates but it gives me stright distance.
How can I calculate driving distance between two locations?
thanks in advance

To calculate the driving distance you'll have to use the Bing Routes API (or Google, but I assume you're using Bing Maps).
There's an example of using the api to find a driving route between two places here: http://msdn.microsoft.com/en-us/library/gg636957.aspx
The general call is:
http://dev.virtualearth.net/REST/V1/Routes/Driving?o=xml&wp.0=location1&wp.1=location2&avoid=minimizeTolls&key=BingMapsKey
You'll have to register for a Bing Maps API key, and then replace location1 and location2 with the locations you like.
The distance should be returned in travelDistance in the json or xml

Related

Xamarin.Forms: how to get driving distance between two points?

My app currently uses Location Services. During debugging, I retrieve my current location using GetLastKnownLocationAsync: myposition.Latitude is 40.758896 while myposition.Latitude is -73.985130.
My SQL Database has a list of Walmart stores, and there's a Walmart with Latitude & Longitude of 40.660992 & -73.7267629.
How can I calculate the driving distance between my set of coordinates and Walmart's coordinates? It would be something like Google Maps' Driving Directions or Waze.
I understand that I can use this SO link to calculate the distance between two sets of point, but I assume apps like Google Maps or Waze consider the actual driving distance between two sets of points. The link above would be great if there were a straight street between two points. Obviously, that's not the case.
I have used Xamarin.Essential library to find the distance between two point
You can use something like this
var location = new Location(21.705723, 72.998199);
var otherLocation = new Location(22.3142, 73.1752);
double distance = location.CalculateDistance(otherLocation,DistanceUnits.Kilometers);

How to get FLIGHT time between two locations using the Google Maps Distance Matrix API?

I need to get travel time by plane between two locations.
In Distance Matrix API there is no Travel Mode like "flight" - https://developers.google.com/maps/documentation/javascript/distancematrix#travel_modes
Any suggestions?
Unfortunately there is no easy way to do this.
However, you could do a trick and estimate the flight time by using geocoding and the geometry library. At least if you don't need real flight data.
The steps would be:
Transform origin and destination from String to LatLng (Geocoding API)
Create markers for each location. (Geometry lib)
Calculate airline distance using computeDistanceBetween (like this: google.maps.geometry.spherical.computeDistanceBetween(path1, path2))
Calculate approximate flight time using average airplane speed.
Hope this helps.
This is sort of a work-around, but an easy one.
Use the measure distance tool in google maps, then for flight time of regular commercial airliners, divide the distance in miles by 500mph to get flight time in hours. For a small propeller plane (like a cessna), use 165mph.

Find street intersections within an area in using Google Maps API

Given a square area, what is the best way to find the approximate coordinates of every street intersection within the given area ?
Since there is no description of your application, I can't tell if you need to use Google Maps or if another data source would answer your needs.
If http://openstreetmap.org fulfills the requirements of your application, then it's easy:
the OSM API has a request to pull data from a rectangular region. You get XML data.
filter this data to keep only the street you are interested in, probably the "key=highway" tags
filter this to keep only the points belonging to two or more lines.
Please disregard this if Google Maps is a requirement.
But still: since the roads exist independently of the database, the above method will yield roads intersections (in lat/long coordinates) with a pretty high correlation with what you would get from Google maps ;-) You can then use those points to display them over a Google map, knowing that both datasets aren't identical so it won't be perfect.
Might not be the easiest method but I used a seperate database of our countries roads with their linestrings.
I took the first and last points of each line string, then counted the number of roads within 50 m of each start/end point. I then took the nodes from navigation route and used these to compare the number of roads intersecting with each node. I then looked at the direction each start point and the next point along that road, which gives you direction. from that with a bit of maths you can work out the number and angle of the roads at the next intersection. I then made a road rules application that tells you which vehicles to give way to

Getting route distance given two geo coordinates

I am creating a windows phone application which uses map control in it. I want to calculate the driving distance between two geo coordinates in windows phone? can any help on this please
You need to work through this example in MSDN Magazine http://msdn.microsoft.com/en-us/magazine/hh148148.aspx
It explains how to do the routing and get the distance property in the results.

Compass - Showing direction based on latitude and longitude

In WP7, is it possible to show compass direction based on the given latitude and longitude values. (For example, if I am in India and if the latitude and longitude values of a place in some other country is given). If yes, please give some idea on how to achieve this.
This is what is known as the Second (inverse) geodetic problem.
"Given two points, determine the azimuth and length of the line
(straight line, arc or geodesic) that connects them." Wikipedia
You can get the distance using System.Device.Location.GeoCoordinate.GetDistanceTo(). Otherwise have a look at the excellent C# Geodesy Library for GPS – Vincenty’s Formulae. In particular the GeodeticCurve.

Resources