02-23-2012, 09:01 AM #1
- 12 Posts
I am creating an app for WP7 that requires the user to find something on a map and somehow point to it. The app will compare the lat/long co-ords that s/he pointed to, to the "correct" lat/long co-ords, to see if s/he found what s/he was meant to find (by checking that the 2 co-ord sets are within a certain distance of each other). Obviously, the zoom level plays a role, so the user will be required to zoom in to a certain point, to make the selection more accurate. My question is twofold: 1) what is the best event to use (not sure click is the best) for the user to tell the app that s/he thinks s/he found what was requested of them; and 2) how can we, from that event, determine the lat/long co-ords that the user found? I realize that it can't be an exact set of co-ords, but a range will do, as will the center of the screen at the point the user triggers the "I found it" event. Any help will be greatly appreciated!
- Retired Moderator
02-24-2012, 03:12 AM #2
- 56 Posts
If I were you, I would have some form of crosshair floating above the map, so they can see where the exact center is of the map. Then have a button in the app bar or below the map that they press once the crosshair is over what they want.
On the click event of that button you can get the maps center by: myMap.TargetCenter which has longitude and latitude.
From there you are going to want to find the distance between the points. But remember that the earth is curved, so you cant just presume that each degree is 100miles etc, because that value changes based on where in the world it is.
For that you can use the haversine formula:
a = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
c = 2.atan2(√a, √(1−a))
d = R.c//click function
var lat1 = mapMain.TargetCenter.Latitude;
var lat2 = //targetlat
var lon1 = mapMain.TargetCenter.Longitude;
var lon2 = //targetlong
var R = 6371; // earth radius in km
var dLat = DegreeToRadians(lat2 - lat1);
var dLon = DegreeToRadians(lon2 - lon1);
lat1 = DegreeToRadians(lat1);
lat2 = DegreeToRadians(lat2);
var a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
Math.Sin(dLon / 2) * Math.Sin(dLon / 2) * Math.Cos(lat1) * Math.Cos(lat2);
var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
var distance = R * c;
private double DegreeToRadians(double angle)
return Math.PI * angle / 180.0;