美文网首页
Mac APP调起Mac的系统地图并传入经纬度展示大头针

Mac APP调起Mac的系统地图并传入经纬度展示大头针

作者: drmi | 来源:发表于2018-11-22 09:22 被阅读10次

    使用场景:类似在Mac版微信中点击一条消息(此消息是某人发送的位置)可以调起系统地图,并且在指定的经纬度插上大头针,搜索框内展示相应的name内容。

    How to open maps App programmatically with coordinates in swift?
    参考链接:
    https://stackoverflow.com/questions/28604429/how-to-open-maps-app-programmatically-with-coordinates-in-swift/28622266

    需要引入:

    import <MapKit/MapKit.h>

    import <CoreLocation/CoreLocation.h>

    这2个框架

    然后在相应的点击事件添加以下代码:
    NSString *name =@"地址名";
    NSString *info = @"地址详情";
    CLLocationDegrees lat = [dic[@"latitude"] doubleValue];
    CLLocationDegrees lon = [dic[@"longitude"] doubleValue];
    CLLocationCoordinate2D coo = CLLocationCoordinate2DMake(lat,lon);
    CLLocationDistance dis = 300;
    MKCoordinateRegion re = MKCoordinateRegionMakeWithDistance(coo, dis, dis);
    MKPlacemark *mark = [[MKPlacemark alloc] initWithCoordinate:coo addressDictionary:@{kABAddressStreetKey:info,kABAddressStateKey:name}];//这里携带的是经纬度,和点击大头针展示的地址名字的地址详情
    MKMapItem *item = [[MKMapItem alloc] initWithPlacemark:mark];
    item.name = name;//这里展示的是系统地图调起后,搜索框里边的内容

    [item openInMapsWithLaunchOptions:@{MKLaunchOptionsMapCenterKey:[NSValue valueWithMKCoordinate:re.center],MKLaunchOptionsMapSpanKey:[NSValue valueWithMKCoordinateSpan:re.span]}];//调起地图展示的地图中心点和范围

    相关文章

      网友评论

          本文标题:Mac APP调起Mac的系统地图并传入经纬度展示大头针

          本文链接:https://www.haomeiwen.com/subject/fhpkqqtx.html