Is there a way to programmatically determine the optimal Bing Maps Zoom Level based on an array of GPS Coordinates? - gps

When programmatically adding an array of GPS Coordinates to a Bing Map, I want to set the Zoom level to the optimal - to show every pushpin/location, but "just barely."
I imagine a way to do this would be to identify the furthest points in the cardinal directions found within the array of coordinates, and then calculate how many miles you need to display both east-to-west and north-to-south.
For example, let's say the furthest north and furthest south locations are determined to be forty miles distant from each other, and the furthest east and furthest west locations are determined to be sixty miles apart from each other. Is there a rule of thumb/calculation/algorithm that would determine what the most "zoomed-in" level would be that would display all of the locations/coordinates, with the "outliers" being as close to the edge of the displayed portion of the map as possible?

You can set a map view with a bounding box, which will automatically determine the zoom level. See the example here
https://www.bing.com/api/maps/sdkrelease/mapcontrol/isdk/setmapviewoptions
using the Bounds property as documented here
https://learn.microsoft.com/en-us/bingmaps/v8-web-control/map-control-api/viewoptions-object

Related

How to customize a mapping method in Network Analyst?

Although it's easy to find the shortest path between two points using NASolver, sometimes NAClassLoader.Load failed to map the points to the right road, NALocator only considers the closest distance.
For example, sometimes we have to judge a point's matching positon according to vehicle's previous tracks, at this time, it will make some mistakes if the loader maps the point to the closet road.
In the graph below, because point1 is on the green road, so point2 should also belongs to the green line but not the red ones. How can I tell the NALocator the right choice? Will NALocatorFeatureAgent work in this condition?

Convert a Lat/Lon coordinate on a map based on preset coordinates

First off, I am not sure if this is the right place so I apologize if this belongs elsewhere - please let me know if it does. I am currently doing some prototyping with this in VB so that's why I come here first.
My Goal
I am trying to make a program to be able to log different types of information for a video game that I play. I would like to be able to map out the entire game with my program and add locations for mobs, resources, etc.
What I have
The in game map can be downloaded so I have literally just stuck this in as a background image on the form (just for now). The map that I get downloaded though is not exactly as the map appears in the game though since the game will add extra water around everything when scrolling around. This makes it a bit tricky to match up where the origin for the map is in game compared to where it would be on the downloaded map.
The nice thing though is that while I am in the game I can print my current coordinates to the screen. So I thought that maybe I can somehow use this to get the right calculation for the rest of the points on the map.
Here is an example image I will refer to now:
In the above map you will see a dotted bounding box. This is an invisible box in the game where once you move your mouse out of the longitude and latitude points will no longer show. This is what I refer to above when I mean I can't find the exact point of origin for the in game map.
You will also see 2 points: A and B. In the game there are teleporters. This is what I would use to get the most accurate position possible. I am thinking I can find the position (in game) of point A and point B and then somehow calculate that into a conversion for my mouse drag event in VB.
In VB the screen starts at top-left and is 0,0. I did already try to get the 2 points like this and just add or subtract the number to the x and y pixel position of the mouse, but it didn't quite line up right.
So with all this information does anyone know if it is possible to write a lon/lat conversion to pixels based on this kind of data?
I appreciate any thoughts and suggestions and if you need any clarification of any information I have posted please let me know and I will be happy to expand on it. I am really hoping I can get this solved!
Thanks!
EDIT:
I also want to mention I am not sure if there is an exact pixel to lat/lon point for the in game map. I.e. the in game map could be 1 pixel = 100 latitude or something. So I might also need to figure out what that conversion number is?
Some clarifications about conversion between the pixel location to 'latitude and longitude'.
First the map in your game is in a geometry coordinate system, which means everything lies in 2D and you can measure the distance between two points by calculate the pixel position.
But when we talk about longitude and latitude, we are actually talking about a geography coordinate system, which is a '3D' model of the sphere oabout the surface of the earth. All the maps on earth are abstracted from 3D to 2D through one step called projection. Like google maps or your GPS. In this projection process, the 3D model converted to 2D model but there is always some part of the map will be tortured, so that same distance in pixels on a map could be different in length in reality.
So if you don't care about the accuracy then you can consider the geometry point as geography point. Otherwise, you need to implement some GIS library to handle the geodesic distance and calculate the geography point based on the projection coordinate system.

GPS bounding box around 2 points

I have 2 GPS locations with a latitude and a longitude.
I want to create a bounding box, which incorporates both these points, plus some number of kilometers of padding on either side (for example, a 10km bounding box which includes both point X and point Y).
I have seen implementations for bounding boxes around 1 singular GPS location, but I have not seen any implementations which incorporate 2 GPS locations.
Can somebody help with an implementation, or the name of a solution?

How to get coordinates of corners of visible bing map?

I'm using Bing Maps in a windows 8 app and I need to display pushpins at numerous locations.
Is there any way to get the GPS coordinates of the corners of the visible map?
Or alternatively a way to get the distance of the visible map? (e.g. 40km width, 60km height)
I need this in order to limit the number of pushpins I attach to the map to just being the ones on the visible part of the map.
You can get this information directly from the Bounds property of the map instance, which returns a LocationRect defined by the Northwest and Southeast lat/lng locations shown in the current view.
http://msdn.microsoft.com/en-us/library/hh846504.aspx
Try using the TryPixelToLocation method.
Location locationOfPixel
if(MyMap.TryPixelToLocation(ThePointToLookUp, out locationOfPixel))
{
//locationOfPixelshould contain the lat/long of the give point on the map.
}
Obviously, you will need to work out what the pixel locations of the top left, top right, bottom left and bottom right of your map control are and pass them in accordingly.

Objective C: How to list set of locations with the nearest geolocation

I have compiled a list of locations with latitude and longitude information. Can I check what is the best approach to filter and populate the list of "nearest" geolocations in a table and mapview based on my current location? (or a destination entered by a user). Also is it also possible to indicate what is the radius I am interested in? e.g. only select all the nearest bookstores within 5km from my location etc
Appreciate your advice on this
Zhen Hoe
Maybe I'm missing something, but why don't you just add your locations to a mapView, and center the map on the user's current location or whereever they want? MapKit will do all the calculations for you, and only show the ones near the center. The user can set their own radius by zooming in and out. MapKit is highly optimized for exactly this purpose, that's how you can see the "rain of pins" in real time.
Update:
You can also go the other way: once you have the annotations on the map, you can query the map for those annotations that are in the visible region with:
- (NSSet *)annotationsInMapRect:(MKMapRect)mapRect
From the docs:
This method offers a fast way to retrieve the annotation objects in a particular portion of the map. This method is much faster than doing a linear search of the objects in the annotations property yourself.
You may find - (CLLocationDistance)distanceFromLocation:(const CLLocation *)location to be very useful
http://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocation_Class/CLLocation/CLLocation.html#//apple_ref/occ/instm/CLLocation/distanceFromLocation:
The haversine formula is frequently used to in navigation for calculating distances between coordinates. This is a pretty decent resource for distance calculations, and even has a code sample for haversine (though it is in Javascript).
If your list of locations is relative small (hundreds, even), you can probably just iterate through the whole list and calculate the distance between each place against current location.