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");
                }
  • 相关阅读:
    jQuery为链接添加链接图像
    jQuery插件Toggle text value
    用ajax清除浏览器缓存的js、css、图片等
    Ajax 解决ie缓存问题
    jQuery插件slidergallery.(仿MAC展示.)
    javascript计算器Calculator
    回车自动提交内容
    个性化表单五技巧
    教你怎么样用CSS和图片做搜索框.
    浅谈css框架开发
  • 原文地址:https://www.cnblogs.com/mancong/p/6117440.html
Copyright © 2011-2022 走看看