zoukankan      html  css  js  c++  java
  • iOS-地图报错超出了经纬度范围Invalid Region

    做地图定位的时候,使用一下代码

                // 经纬度
                CLLocationDegrees latitude = [storeDict[@"lat"] doubleValue];
                CLLocationDegrees longitude = [storeDict[@"lon"] doubleValue];
                
                CLLocationCoordinate2D centerCoord = (CLLocationCoordinate2D){latitude, longitude};
                MKCoordinateSpan span;
                span.latitudeDelta=0.01;
                span.longitudeDelta=0.01;
                MKCoordinateRegion region={centerCoord,span};
                [self.mapView setRegion:region animated:true];

    报错信息: 

    Exception : 'Invalid Region <center:+inf, +0.00000000 span:+1.00000000, +0.50000000>' when trying to display the map

    错误问题解释: Invalid Region 的意思是无效的区域.使用的经纬度超出了规定的经纬度范围.跑出的错误.

    扫盲一下地理知识(我也是百度的...)

     经度0°——180°(东行,标注E)0°——180°(西行,标注W)
     纬度0°——90°N、0°——90°S

    也就是说纬度的范围 -90 <= latitude <= 90   经度的范围是 -180 <= longitude <= 180

    找到错误原因:后台把经纬度写反了...本来纬度应该是31.190606错写成经度121.443078.

    解决办法: 加上判断

                if ((region.center.latitude >= -90) && (region.center.latitude <= 90) && (region.center.longitude >= -180) && (region.center.longitude <= 180))
                {
                    [self.mapView setRegion:region animated:true];
                }
                else
                {
                    NSLog(@"invilid region");
                }
  • 相关阅读:
    IIS7.x经典模式与集成模式
    pocketsphinx实现连续大词汇量语音识别
    js对象冒充实现的继承
    你不得不知道的HTML5的新型标签
    (译)开发优秀的虚拟现实体验:从开发I Expect You to Die中总结的六个要点
    《构建之法》阅读梳理篇读后感
    VR介绍
    推荐
    VR设备
    开发VR游戏的基本要求
  • 原文地址:https://www.cnblogs.com/mancong/p/6117440.html
Copyright © 2011-2022 走看看