app修改地图 ios
2016-11-15 11:11:31 happy66336 阅读数 973

选择背景:由于地图的SDK一般较大,在app内部实现线路规划、导航等功能比较麻烦,而且耗时,所以就选择在app内部唤起地图app(如高德地图、百度地图、腾讯地图、苹果地图等)以实现同样的功能。

效果见下图:

这里写图片描述
IMG_0330.PNG

代码如下:(具体会根据手机上安装的地图app来显示)

#pragma mark - 选择导航app
- (void)actionBtnClick {
    //当前的位置
    CLLocationCoordinate2D currentLoc = self.mapView.userLocation.location.coordinate;
    MKPlacemark *curPlacemark = [[MKPlacemark alloc] initWithCoordinate:currentLoc addressDictionary:nil];
    MKMapItem *curLocationItem = [[MKMapItem alloc] initWithPlacemark:curPlacemark];
    curLocationItem.name = @"当前位置";
    //目的地的位置
    CLLocationCoordinate2D toLocation;
    toLocation.longitude = _longi.floatValue;
    toLocation.latitude = _lati.floatValue;
    MKPlacemark *toPlacemark = [[MKPlacemark alloc] initWithCoordinate:toLocation addressDictionary:nil];
    MKMapItem *toLocationItem = [[MKMapItem alloc] initWithPlacemark:toPlacemark];
    toLocationItem.name = _shopName;
    //选择要唤起的app
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]) {
        UIAlertAction *daode = [UIAlertAction actionWithTitle:@"高德地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSString *urlString = [[NSString stringWithFormat:@"iosamap://path?sourceApplication=ApplicationName&sid=BGVIS1&slat=%f&slon=%f&sname=当前位置&did=BGVIS2&dlat=%f&dlon=%f&dname=%@&dev=0&m=0&t=0", currentLoc.latitude, currentLoc.longitude, _lati.floatValue, _longi.floatValue, _shopName] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            [CGOpenUrlTool openUrl:[NSURL URLWithString:urlString]];
        }];
        [alert addAction:daode];
    }
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]]) {
        UIAlertAction *baidu = [UIAlertAction actionWithTitle:@"百度地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin=%f,%f&destination=latlng:%f,%f|name=%@&mode=driving&coord_type=gcj02",currentLoc.latitude, currentLoc.longitude, _lati.floatValue, _longi.floatValue, _shopName] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            [CGOpenUrlTool openUrl:[NSURL URLWithString:urlString]];
        }];
        [alert addAction:baidu];
    }
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"qqmap://"]]) {
        UIAlertAction *tencent = [UIAlertAction actionWithTitle:@"腾讯地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSString *urlString = [[NSString stringWithFormat:@"qqmap://map/routeplan?from=当前位置&fromcoord=%f,%f&type=drive&tocoord=%f,%f&to=%@&coord_type=1&policy=0", currentLoc.latitude, currentLoc.longitude, _lati.floatValue, _longi.floatValue, _shopName] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            [CGOpenUrlTool openUrl:[NSURL URLWithString:urlString]];
        }];
        [alert addAction:tencent];
    }
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"http://maps.apple.com/"]]) {
        UIAlertAction *apple = [UIAlertAction actionWithTitle:@"苹果地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

            NSArray *items = @[curLocationItem,toLocationItem];
            NSDictionary *options = @{
                                  MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDefault,
                                  MKLaunchOptionsMapTypeKey : @(MKMapTypeStandard),
                                  MKLaunchOptionsShowsTrafficKey : @(YES)
                                  };

            //打开苹果自身地图应用,并呈现特定的item
            [MKMapItem openMapsWithItems:items launchOptions:options];
        }];
        [alert addAction:apple];
    }
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

    }];
    [alert addAction:cancel];
    [self presentViewController:alert animated:YES completion:nil];
}

详细内容请到我的简书查看

2017-06-19 17:40:00 weixin_33701617 阅读数 63
1151942-faf779c66ae6daa5.png

图片1

1151942-3e3635be65f39ec9.png

图片2

1151942-dc0a0db5b4241d20.png

A29D76E0-5C52-47E3-B0FA-B4EDBF91DC94.png

1151942-cf298641ddef9a74.png

图片4

1151942-bfc78cb9b2473542.png

图片5

1151942-86a6905c76c2ca43.png

图片6

最后 Command+ B 编译一下 ! 好了 Cmd+R 运行一下看下咯

2015-04-19 11:19:58 lf644206005 阅读数 509

我们一开始初建app,我们模拟器和真机上显示的都是我们的项目名称,但是后来我们想改app名称,似乎看网上大多数教程都太复杂了。现在小笔提供一个只是修改app显示名称的方法:
直接在Info.plist中添加或者修改Bundle display name即可

2017-09-23 14:21:11 u010960265 阅读数 3070

在info.plist文件中添加key值Bundle display name+app名称


君凯商联网-iOS-字唐名僧

没有更多推荐了,返回首页