Sfoglia il codice sorgente

1.增加地图导航模块。

Pen Li 7 anni fa
parent
commit
ca2235a221

+ 16 - 0
common/MapNavigation/RAMapNavigateHandler.h

@@ -0,0 +1,16 @@
+//
+//  RAMapNavigateHandler.h
+//  APEX CRM
+//
+//  Created by Jack on 2018/11/29.
+//  Copyright © 2018年 USAI. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface RAMapNavigateHandler : NSObject
+
++ (void)ra_navigate:(NSString *)addr withTitle:(NSString *)title viewController:(UIViewController *)vc;
+
+@end
+

+ 63 - 0
common/MapNavigation/RAMapNavigateHandler.m

@@ -0,0 +1,63 @@
+//
+//  RAMapNavigateHandler.m
+//  APEX CRM
+//
+//  Created by Jack on 2018/11/29.
+//  Copyright © 2018年 USAI. All rights reserved.
+//
+
+#import "RAMapNavigateHandler.h"
+#import <MapKit/MapKit.h>
+#import <AddressBook/AddressBook.h>
+
+@implementation RAMapNavigateHandler
+
++ (void)ra_navigate:(NSString *)addr withTitle:(NSString *)title viewController:(UIViewController *)vc {
+    if (vc) {
+        
+        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleActionSheet];
+        
+        if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]) {
+            
+            UIAlertAction *googleMapAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Google Map", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+                
+                NSString *urlString = [[NSString stringWithFormat:@"comgooglemaps://?q=%@&directionsmode=driving",addr]
+                                       stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
+                
+                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:^(BOOL success) {
+                    NSLog(@"%u",success);
+                }];
+                
+                //            NSString *urlString = [[NSString stringWithFormat:@"comgooglemaps://?center=37.782652,-122.410126&directionsmode=driving"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+                //            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
+                
+            }];
+            [alertVC addAction:googleMapAction];
+        }
+        
+        UIAlertAction *appleMapAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Apple Map", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            
+            MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
+            
+            MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:kCLLocationCoordinate2DInvalid
+                                                                                               addressDictionary:@{
+                                                                                                                   (__bridge id)kABPersonAddressStreetKey : addr
+                                                                                                                   }]];
+            [MKMapItem openMapsWithItems:@[currentLocation, toLocation] launchOptions:@{
+                                                                                        MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,
+                                                                                        MKLaunchOptionsShowsTrafficKey: @(YES)
+                                                                                        }];
+            
+        }];
+        [alertVC addAction:appleMapAction];
+        
+        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
+            
+        }];
+        [alertVC addAction:cancelAction];
+        
+        [vc presentViewController:alertVC animated:YES completion:nil];
+    }
+}
+
+@end