im trying to fit 2 pois on a bing map for WinRT Universal APP, commonly user position and any other point, so the user can see the map between two points, i have this code:
private void centerMap(Geoposition pos, MapPoi pos2)
{
try {
#if WINDOWS_APP
//TODO PC Maps
#elif WINDOWS_PHONE_APP
GeoboundingBox geoboundingBox = new Windows.Devices.Geolocation.GeoboundingBox(
new BasicGeoposition() { Latitude = pos.Coordinate.Latitude, Longitude = pos.Coordinate.Longitude },
new BasicGeoposition() { Latitude = pos2.lat, Longitude = pos2.lng });
map1._map.TrySetViewBoundsAsync(geoboundingBox,null,MapAnimationKind.Linear);
#endif
}catch(Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
So one more time i have a problem i cannot solve myself.
First i need to understand something that i must be doing bad, im getting System.ArgumentException on the GeoboundingBox constructor, here stack trace:
A first chance exception of type 'System.ArgumentException' occurred in EspartAPP.WindowsPhone.exe
System.ArgumentException: Value does not fall within the expected range.
at Windows.Devices.Geolocation.GeoboundingBox..ctor(BasicGeoposition northwestCorner, BasicGeoposition southeastCorner)
at EspartAPP.Modulos.Modulo_Mapa.centerMap(Geoposition pos, MapPoi pos2)
Here are the coordinates used for the test:
pos var: Lat 40.4564664510315 lng -3.65939843190291
pos2 var: Lat 40.4579103 lngs -3.6532357
Both coordinates are correct, one is the user position just got from gps, the other is a close location.
I cant understand what can be going bad, there must be something that i need to know.
The code i posted just throw that exception, but, if i just do +1 to the pos latitude it works, and seems to be doing it right.
If i add pos2 first (as northwestCorner) it doesnt throw exception, it zooms out to max so i can almost see the entire map (which is obviously wrong)
There must be some rules im ignoring, maybe i have to calc which coordinate should be on northwest position?
EDIT: Was exactly that, working code:
private void centerMap(Geoposition pos, MapPoi pos2)
{
try {
BasicGeoposition nw = new BasicGeoposition();
nw.Latitude = Math.Max(pos.Coordinate.Latitude, pos2.lat);
nw.Longitude = Math.Min(pos.Coordinate.Longitude, pos2.lng);
BasicGeoposition se = new BasicGeoposition();
se.Latitude = Math.Min(pos.Coordinate.Latitude, pos2.lat);
se.Longitude = Math.Max(pos.Coordinate.Longitude, pos2.lng);
#if WINDOWS_APP
//TODO PC Maps
#elif WINDOWS_PHONE_APP
GeoboundingBox geoboundingBox = new Windows.Devices.Geolocation.GeoboundingBox(nw,se);
map1._map.TrySetViewBoundsAsync(geoboundingBox,null,MapAnimationKind.Bow);
#endif
}catch(Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
Sorry for my bad english and problems with this bing maps, this is really poor documented i expect because its the newer API and its a mess to find what you need for the API you are working for.
Thanks in advance.