Commit 6dc5cb25 authored by Deployer's avatar Deployer

Added example for reverse geocoding

parent 767c85af
......@@ -9,7 +9,7 @@
Pod::Spec.new do |s|
s.name = 'CedarMaps'
s.version = '1.0.1'
s.version = '1.0.2'
s.cocoapods_version = '>= 0.36'
s.license = 'MIT'
s.homepage = 'https://www.kikojas.com/about-cedarmaps'
......
......@@ -12,6 +12,8 @@
@interface CSBookmarksViewController () <MGLMapViewDelegate>
@property (nonatomic, strong) CSMapKit *mapKit;
@end
#pragma mark - CSViewController Implementation
......@@ -24,12 +26,12 @@
[super viewDidLoad];
CSAuthenticationManager *auth = [CSAuthenticationManager sharedManager];
[auth setCredentialsWithClientID:@"clientID"
clientSecret:@"clientSecret"];
[auth setCredentialsWithClientID:nil
clientSecret:nil];
CSMapKit *mapKit = [[CSMapKit alloc] initWithMapID:@"cedarmaps.streets"];
self.mapKit = [[CSMapKit alloc] initWithMapID:@"cedarmaps.streets"];
[mapKit styleURLWithCompletion:^(NSURL *url) {
[self.mapKit styleURLWithCompletion:^(NSURL *url) {
dispatch_async(dispatch_get_main_queue(), ^{
self.mapView.styleURL = url;
});
......@@ -43,13 +45,28 @@
{
[super viewDidAppear:animated];
// [self markBusStation];
// [self markTrainStation];
// [self markPointNumberOne];
// [self markPointNumberTwo];
// [self markPointNumberThree];
[self markBusStation];
[self markTrainStation];
[self markPointNumberOne];
[self markPointNumberTwo];
[self markPointNumberThree];
[self.mapKit reverseGeocodingWithCoordinate:CLLocationCoordinate2DMake(35.770889877650724, 51.439468860626214) completion:^(NSDictionary *result, NSError *error) {
NSString *city = result[@"city"];
NSString *locality = result[@"locality"];
NSString *address = result[@"address"];
dispatch_async(dispatch_get_main_queue(), ^{
MGLPointAnnotation *point = [[MGLPointAnnotation alloc] init];
point.coordinate = CLLocationCoordinate2DMake(35.770889877650724, 51.439468860626214);
point.title = [NSString stringWithFormat:@"%@، %@، %@", city, locality, address];
point.subtitle = nil;
[self.mapView addAnnotation:point];
});
}];
}
#pragma mark
......@@ -62,6 +79,9 @@
#pragma mark - MGLMapViewDelegate Methods
- (MGLAnnotationImage *)mapView:(MGLMapView *)mapView imageForAnnotation:(id<MGLAnnotation>)annotation {
if (!annotation.subtitle) {
return nil;
}
MGLAnnotationImage *image = [MGLAnnotationImage annotationImageWithImage:[UIImage imageNamed:annotation.subtitle] reuseIdentifier:annotation.subtitle];
return image;
}
......
......@@ -12,14 +12,14 @@ import CedarMaps
class CSBookmarksViewController: UIViewController {
@IBOutlet weak var mapView: MGLMapView!
let mapKit = CSMapKit(mapID: "cedarmaps.streets")
override func viewDidLoad() {
super.viewDidLoad()
let auth = CSAuthenticationManager.shared()
auth?.setCredentialsWithClientID("clientID", clientSecret: "clientSecret")
auth?.setCredentialsWithClientID(nil, clientSecret: nil)
let mapKit = CSMapKit(mapID: "cedarmaps.streets")
mapKit?.styleURL(completion: { (url) in
DispatchQueue.main.async {
self.mapView.styleURL = url
......@@ -33,11 +33,28 @@ class CSBookmarksViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
markBusStation()
markTrainStation()
markPointNumberOne()
markPointNumberTwo()
markPointNumberThree()
// markBusStation()
// markTrainStation()
// markPointNumberOne()
// markPointNumberTwo()
// markPointNumberThree()
mapKit?.reverseGeocoding(with: CLLocationCoordinate2DMake(35.770889877650724, 51.439468860626214), completion: { (result, error) in
let city = result?["city"] as? String
let locality = result?["locality"] as? String
let address = result?["address"] as? String
DispatchQueue.main.async {
let point = MGLPointAnnotation()
point.coordinate = CLLocationCoordinate2DMake(35.770889877650724, 51.439468860626214)
point.title = "\(city ?? "شهر یافت نشد")، \(locality ?? "محله یافت نشد")، \(address ?? "آدرس یافت نشد")"
point.subtitle = nil
self.mapView.addAnnotation(point)
}
})
}
@IBAction func attributionDidTouchUpInside(_ sender: UIButton?) {
......@@ -49,7 +66,8 @@ class CSBookmarksViewController: UIViewController {
extension CSBookmarksViewController: MGLMapViewDelegate {
func mapView(_ mapView: MGLMapView, imageFor annotation: MGLAnnotation) -> MGLAnnotationImage? {
let image = MGLAnnotationImage(image: UIImage(named: annotation.subtitle!!)!, reuseIdentifier: annotation.subtitle!!)
guard let s1 = annotation.subtitle, let s2 = s1 else { return nil }
let image = MGLAnnotationImage(image: UIImage(named: s2)!, reuseIdentifier: annotation.subtitle!!)
return image
}
......@@ -57,6 +75,7 @@ extension CSBookmarksViewController: MGLMapViewDelegate {
return true
}
fileprivate func markBusStation() {
let annotation = MGLPointAnnotation()
annotation.coordinate = CLLocationCoordinate2DMake(35.770889877650724, 51.439468860626214)
......
......@@ -215,7 +215,9 @@
NSDictionary *output = [NSDictionary dictionary];
if ([json.allKeys containsObject:@"result"]) {
NSDictionary *result = [json objectForKey:@"result"];
output = result;
completion(result, nil);
} else {
completion(output, nil);
}
}
else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment