其中经度/纬度的调整,我需要扩大我的地图向西北和东南? [英] Which longitude/latitude adjustments do I need to enlarge my map to the northwest and to the southeast?

查看:201
本文介绍了其中经度/纬度的调整,我需要扩大我的地图向西北和东南?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是有关的我前面



问题

我想补充一个垫片我的地图,这样极端的图钉没有半边界内,一半出界外。我是在正确的轨道(没有双关语意),但我的逻辑是错误的。我写这个方法:

  //从Brundritt和Boonaert改编:http://stackoverflow.com/questions/26937358/can -i调整,我的兵 - 地图 - 视图 -  locationrect-包围盒按一个小数额
公共静态位置GetAShimLocation(IList的<地点>的位置,布尔IsForNorthwestCorner)
{
常量双MAP_CUSHION = 0.1; //这是一个足够舒适坐垫?
//我不知道为什么拉特是85而不是90
双maxLat = -85;
双minL​​at = 85;
双maxLon = -180;
双MINLON = 180;

的foreach(在位置位置LOC)
{
如果(loc.Latitude> maxLat)
{
maxLat = loc.Latitude;
}

如果(loc.Latitude< minLat)
{
minLat = loc.Latitude;
}

如果(loc.Longitude> maxLon)
{
maxLon = loc.Longitude;
}

如果(loc.Longitude< MINLON)
{
MINLON = loc.Longitude;
}
}
位置retLoc =新位置();
//我不知道这道数学是正确的 - 测试后
如果(IsForNorthwestCorner)
{
retLoc.Latitude = maxLat - MAP_CUSHION;
retLoc.Longitude = maxLon - MAP_CUSHION;
}
,否则//东南角 - 舒展了一下两个方向
{
retLoc.Latitude = minLat + MAP_CUSHION;
retLoc.Longitude = MINLON + MAP_CUSHION;
}
返回retLoc;
}



...并调用它像这样:

 私人无效ResizeMap()
{
App.photosetLocationCollection.Add(
PhotraxUtils.GetAShimLocation(App.photosetLocationCollection,真));
App.photosetLocationCollection.Add(
PhotraxUtils.GetAShimLocation(App.photosetLocationCollection,FALSE));
photraxMap.SetView(新LocationRect(App.photosetLocationCollection));
}



...它的确实的改变大小该地图而添加垫片的地点为图钉,但而不是拉动映射了一个小北部和西部,以及南部和东部,它似乎是垂直挤压它(减少纬度范围内)和横向拉伸它(增加经度)。



我真的需要这里什么最小值和最大值,负和的组合加呢?



要总结:我要找的是拉伸的远一点,从西北西北角和东南角远一点东南地图



一个50点(或以上)后的,其实赏金谁的数字了这一点。



更新



这是集简Kukacka的代码,并与坐垫玩弄,直到我找到了正要右后; 。情况因人而异(没有双关语意)

 公共静态位置GetAShimLocation(IList的<地点>的位置,布尔IsForNorthwestCorner)
{
常量双MAP_CUSHION = 1.05; //这似乎是完美的约
//双maxLat = -85; < =这是原来的(广告[A,O] PTED)代码是,我不知道为什么,而不是85 90,虽然
//双minL​​at = 85;
双maxLat = -90;
双minL​​at = 90;
双maxLon = -180;
双MINLON = 180;

的foreach(在位置位置LOC)
{
如果(loc.Latitude> maxLat)
{
maxLat = loc.Latitude;
}

如果(loc.Latitude< minLat)
{
minLat = loc.Latitude;
}

如果(loc.Longitude> maxLon)
{
maxLon = loc.Longitude;
}

如果(loc.Longitude< MINLON)
{
MINLON = loc.Longitude;
}
}
位置retLoc =新位置();

双latDif = Math.Abs​​(maxLat - minLat);
双lonDif = Math.Abs​​(maxLon - MINLON);
//这从一月Kukacka逻辑http://stackoverflow.com/questions/26948104/which-longitude-latitude-adjustments-do-i-need-to-enlarge-my-map-to-the-northwes
如果(IsForNorthwestCorner)
{
retLoc.Latitude = maxLat - MAP_CUSHION * latDif;
retLoc.Longitude = maxLon - MAP_CUSHION * lonDif;
}
,否则//东南角 - 舒展了一下两个方向
{
retLoc.Latitude = minLat + MAP_CUSHION * latDif;
retLoc.Longitude = MINLON + MAP_CUSHION * lonDif;
}
//边缘的情况下保险
如果(retLoc.Latitude> 90.0)
{
retLoc.Latitude = 90.0;
}
,否则如果(retLoc.Latitude< -90.0)
{
retLoc.Latitude = -90.0;
}

如果(retLoc.Longitude> 180.0)
{
retLoc.Latitude = 180.0;
}
,否则如果(retLoc.Longitude< -180.0)
{
retLoc.Longitude = -180.0;
}
返回retLoc;
}


解决方案

我不知道怎么做地图看挤压,不过你的靠垫应该是比较大小,例如。地图大小的10%。尝试是这样的:

 双latDif = Math.Abs​​(maxLat  -  minLat); 
双lonDif = Math.Abs​​(maxLon - MINLON);
如果(IsForNorthwestCorner)
{
retLoc.Latitude = maxLat - MAP_CUSHION * latDif;
retLoc.Longitude = maxLon - MAP_CUSHION * lonDif;
}
,否则//东南角 - 舒展了一下两个方向
{
retLoc.Latitude = minLat + MAP_CUSHION * latDif;
retLoc.Longitude = MINLON + MAP_CUSHION * lonDif;
}


This is related to my earlier question

I want to add a "shim" to my map so that the extreme pushpins aren't half-in bounds, half out-of-bounds. I'm on the right track (no pun intended), but my logic is faulty. I wrote this method:

// Adapted from Brundritt and Boonaert: http://stackoverflow.com/questions/26937358/can-i-adjust-my-bing-maps-view-locationrect-bounding-box-by-a-small-amount
public static Location GetAShimLocation(IList<Location> locations, bool IsForNorthwestCorner)
{
    const double MAP_CUSHION = 0.1; // Is this a comfortable enough cushion?
    // I don't know why the Lats are 85 instead of 90
    double maxLat = -85;
    double minLat = 85;
    double maxLon = -180;
    double minLon = 180;

    foreach (Location loc in locations)
    {
        if (loc.Latitude > maxLat)
        {
            maxLat = loc.Latitude;
        }

        if (loc.Latitude < minLat)
        {
            minLat = loc.Latitude;
        }

        if (loc.Longitude > maxLon)
        {
            maxLon = loc.Longitude;
        }

        if (loc.Longitude < minLon)
        {
            minLon = loc.Longitude;
        }
    }
    Location retLoc = new Location();
    // I'm not sure this math is right - test it later
    if (IsForNorthwestCorner)
    {
        retLoc.Latitude = maxLat - MAP_CUSHION;
        retLoc.Longitude = maxLon - MAP_CUSHION;
    }
    else // SouthEast corner - stretch a little both directions
    {
        retLoc.Latitude = minLat + MAP_CUSHION;
        retLoc.Longitude = minLon + MAP_CUSHION;
    }
    return retLoc;
}

...and call it like so:

private void ResizeMap()
{         
    App.photosetLocationCollection.Add(
        PhotraxUtils.GetAShimLocation(App.photosetLocationCollection, true));            
    App.photosetLocationCollection.Add(
        PhotraxUtils.GetAShimLocation(App.photosetLocationCollection, false));
    photraxMap.SetView(new LocationRect(App.photosetLocationCollection));
}

...and it does alter the size of the map without adding the "shim" locations as pushpins, but instead of pulling the map up a little north and west, and also south and east, it seems to be squashing it vertically (reducing latitude scope) and stretching it horizontally (increasing longitude).

What combination of min and max and minus and plus do I really need here?

To sum up: what I'm looking for is to "stretch" the map a little further northwest from the northwest corner and a little further southeast from the southeast corner.

A 50-point (or more) after-the-fact bounty to whoever figures this out.

UPDATE

Here it is after incorporating Jan Kukacka's code, and playing around with the cushion until I found what was about right; YMMV (no pun intended).

public static Location GetAShimLocation(IList<Location> locations, bool IsForNorthwestCorner)
{
    const double MAP_CUSHION = 1.05; // This seems to be about perfect
    //double maxLat = -85; <= This is what the original (ad[a,o]pted) code was, I don't know why 85 instead of 90, though
    //double minLat = 85;
    double maxLat = -90;
    double minLat = 90;
    double maxLon = -180;
    double minLon = 180;

    foreach (Location loc in locations)
    {
        if (loc.Latitude > maxLat)
        {
            maxLat = loc.Latitude;
        }

        if (loc.Latitude < minLat)
        {
            minLat = loc.Latitude;
        }

        if (loc.Longitude > maxLon)
        {
            maxLon = loc.Longitude;
        }

        if (loc.Longitude < minLon)
        {
            minLon = loc.Longitude;
        }
    }
    Location retLoc = new Location();

    double latDif = Math.Abs(maxLat - minLat);
    double lonDif = Math.Abs(maxLon - minLon);
    // This logic from Jan Kukacka http://stackoverflow.com/questions/26948104/which-longitude-latitude-adjustments-do-i-need-to-enlarge-my-map-to-the-northwes
    if (IsForNorthwestCorner)
    {
        retLoc.Latitude = maxLat - MAP_CUSHION * latDif;
        retLoc.Longitude = maxLon - MAP_CUSHION * lonDif;
    }
    else // SouthEast corner - stretch a little both directions
    {
        retLoc.Latitude = minLat + MAP_CUSHION * latDif;
        retLoc.Longitude = minLon + MAP_CUSHION * lonDif;
    }
    // Edge case insurance
    if (retLoc.Latitude > 90.0)
    {
        retLoc.Latitude = 90.0;
    }
    else if (retLoc.Latitude < -90.0)
    {
        retLoc.Latitude = -90.0;
    }

    if (retLoc.Longitude > 180.0)
    {
        retLoc.Latitude = 180.0;
    }
    else if (retLoc.Longitude < -180.0)
    {
        retLoc.Longitude = -180.0;
    }
    return retLoc;
}

解决方案

I am not sure how does your map look "squashed", nevertheless your cushion should be relatively sized, eg. 10% of the map size. Try something like this:

 double latDif = Math.Abs(maxLat - minLat);
 double lonDif = Math.Abs(maxLon - minLon);
 if (IsForNorthwestCorner)
 {
     retLoc.Latitude = maxLat - MAP_CUSHION * latDif;
     retLoc.Longitude = maxLon - MAP_CUSHION * lonDif;
 }
 else // SouthEast corner - stretch a little both directions
 {
     retLoc.Latitude = minLat + MAP_CUSHION * latDif;
     retLoc.Longitude = minLon + MAP_CUSHION * lonDif;
 }

这篇关于其中经度/纬度的调整,我需要扩大我的地图向西北和东南?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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