【问题标题】:set user location on map by coding通过编码在地图上设置用户位置
【发布时间】:2015-04-18 11:01:47
【问题描述】:

有没有办法通过代码设置mapView.userLocation.location.coordinate?

我知道有 CLLocationCoordinate2D 用于设置坐标,但它不是 userLocationCoordinate。

我尝试为mapView.userLocation.coordinate.latitude 分配一个数字,但随后我得到“此表达式不可分配”

mapView.userLocation.coordinate.latitude = 0;

那么有没有办法设置 UserLocation(除了在模拟器中设置默认位置)?

【问题讨论】:

    标签: ios objective-c xcode mkmapview cllocationcoordinate2d


    【解决方案1】:

    可能无法在其定义中设置MKUserLocation,因为它表明它是readonly 属性。

     // The annotation representing the user's location
     @property (nonatomic, readonly) MKUserLocation *userLocation;
    

    您可以在

    中添加MKAnnotationView而不是这个
     -(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
    

    您要突出显示的位置,例如用户位置,

    愿它对你有所帮助。

    HTH,享受编码!

    【讨论】:

      【解决方案2】:

      您不能通过代码设置用户的当前位置,因为它是只读属性。

      如果你想要用户的当前位置,你可以使用 CLLocationManager。 请参阅下面的链接 Link 1 Link 2

      或者您可以使用 gpx 文件来设置设备的当前位置。 为此,请参考link

      希望这会对你有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-02-18
        • 2023-04-03
        • 2020-02-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多