值不在预期范围内GeoboundingBox WinRT [英] Value does not fall within the expected range GeoboundingBox WinRT

查看:103
本文介绍了值不在预期范围内GeoboundingBox WinRT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在WinRT Universal APP的bing地图上拟合2 pois,通常是用户位置和任何其他点,所以用户可以看到两点之间的地图,我有此代码:

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.

首先,我需要了解我必须做的不好的事情,即在GeoboundingBox构造函数上获取System.ArgumentException,这里是堆栈跟踪:

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

两个坐标都是正确的,一个是刚刚从gps获得的用户位置,另一个是附近位置.

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.

我发布的代码只是抛出了该异常,但是,如果我只是对pos纬度进行+1,则它可以工作,并且似乎做得对.

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.

如果我先添加pos2(如northwestCorner),它不会抛出异常,它会放大到最大,这样我几乎可以看到整个地图(显然是错误的)

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)

必须忽略一些规则,也许我必须计算哪个坐标应该在西北位置?

就是这样,工作代码:

 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());
    }
    }

对不起,我的英语不好,并且对此bing地图存在问题,我希望这确实记录不佳,因为它的API较新,而且混乱不堪,无法找到您正在使用的API的需求.

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.

谢谢.

推荐答案

您没有提供正确的坐标.您可以在此处阅读,第一个坐标必须位于区域(西北坐标),第二个必须是右下角(东南坐标).您的pos是左下角,pos2是右上角.

You are not providing the correct coordinates. As you can read here the first coordinate must be upper left corner of the region (the north west coordinate), the second must be the lower right corner (the south east coordinate). Your pos is the lower left corner and pos2 is the upper right corner.

您将获得正确的坐标,如下所示:

You get the right coordinates like this:

var nw = new BasicGeoposition();
nw.Latitude = Max(pos.Coordinate.Latitude, pos2.lat);
nw.Longitude = Min(pos.Coordinate.Longitude, pos2.lng);
var se = new BasicGeoposition();
se.Latitude = Min(pos.Coordinate.Latitude, pos2.lat);
se.Longitude = Max(pos.Coordinate.Longitude, pos2.lng);

这篇关于值不在预期范围内GeoboundingBox WinRT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆