Commit 442e1d7b authored by Deployer's avatar Deployer

Updated mapbox to version 3.3. Added Swift example

parent 1d154e86
......@@ -8,24 +8,19 @@
#
Pod::Spec.new do |s|
s.name = "CedarMaps"
s.version = "0.1.6"
s.summary = "Cedar Studio iOS SDK"
s.description = "Cedar Studio should write something to introduce their Pod."
s.homepage = "http://cedar.ir"
s.name = 'CedarMaps'
s.version = '1.0.0'
s.cocoapods_version = '>= 0.36'
s.license = 'MIT'
s.author = { "Emad A." => "emad310@gmail.com" }
s.source = { :git => "http://gitlab.cedar.ir/cedar.studios/cedarmaps-sdk-ios-public.git", :tag => s.version.to_s }
s.platform = :ios, '7.1'
s.requires_arc = true
s.homepage = 'https://www.kikojas.com/about-cedarmaps'
s.authors = { 'Emad A.' => 'emad310@gmail.com', 'Saeed T' => 'saeed.taheri@gmail.com' }
s.summary = 'CedarMaps iOS SDK'
s.source = { :git => 'http://gitlab.cedar.ir/cedar.studios/cedarmaps-sdk-ios-public.git', :tag => s.version.to_s }
s.source_files = 'Pod/Classes'
s.resource_bundles = {
'CedarMap' => ['Pod/Assets/*.png']
}
s.framework = 'UIKit'
s.platform = :ios, '8.0'
s.requires_arc = true
s.resource_bundles = { 'CedarMap' => ['Pod/Assets/*.png' ] }
s.public_header_files = 'Pod/Classes/**/*.h'
s.frameworks = 'UIKit'
s.dependency 'Mapbox-iOS-SDK', '1.6.0'
s.dependency 'Mapbox-iOS-SDK', '~> 3.3.4'
end
\ No newline at end of file
source 'https://github.com/CocoaPods/Specs.git'
target 'CedarMaps' do
pod 'CedarMaps', :git => 'http://gitlab.cedar.ir/cedar.studios/cedarmaps-sdk-ios-public.git'
end
target 'Tests' do
pod 'CedarMaps', :git => 'http://gitlab.cedar.ir/cedar.studios/cedarmaps-sdk-ios-public.git'
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_STRICT_OBJC_MSGSEND'] = 'NO'
end
end
end
\ No newline at end of file
PODS:
- CedarMaps (0.1.5):
- Mapbox-iOS-SDK (~> 1.5.0)
- FMDB (2.3):
- FMDB/standard (= 2.3)
- FMDB/common (2.3)
- FMDB/standard (2.3):
- FMDB/common
- GRMustache (6.8.3):
- JRSwizzle (~> 1.0)
- JRSwizzle (1.0)
- Mapbox-iOS-SDK (1.5.1):
- FMDB (= 2.3)
- GRMustache (= 6.8.3)
- SMCalloutView (= 2.0)
- SMCalloutView (2.0)
DEPENDENCIES:
- CedarMaps (from `http://gitlab.cedar.ir/cedar.studios/cedarmaps-sdk-ios-public.git`)
EXTERNAL SOURCES:
CedarMaps:
:git: http://gitlab.cedar.ir/cedar.studios/cedarmaps-sdk-ios-public.git
CHECKOUT OPTIONS:
CedarMaps:
:commit: 6f85015ad7a9219a7049d1dc96d73a45eb1db608
:git: http://gitlab.cedar.ir/cedar.studios/cedarmaps-sdk-ios-public.git
SPEC CHECKSUMS:
CedarMaps: cdb5e7b32a3a48cafa2bbb6f1b14c8cf181e8b35
FMDB: e78c5941bb10563f2b707255119e3655e790c29e
GRMustache: 3840864eb8c23b07bbdbcbc469f11bb1210d6f13
JRSwizzle: dd5ead5d913a0f29e7f558200165849f006bb1e3
Mapbox-iOS-SDK: c8f6353fb999a6b6fb22856a6d26ba36c3c87fd1
SMCalloutView: f758edd824b18bf4f42de00df1e299861a2d1950
PODFILE CHECKSUM: 5645086d63b7607a7b89b38c279867437e2d5bdd
COCOAPODS: 1.0.0.beta.3
//
// Prefix header
//
// The contents of this file are implicitly included at the beginning of every test case source file.
//
#ifdef __OBJC__
#endif
//
// CedarMapTests.m
// CedarMapTests
//
// Created by Emad A. on 01/19/2015.
// Copyright (c) 2014 Emad A.. All rights reserved.
//
${TEST_EXAMPLE}
/* Localized versions of Info.plist keys */
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
......
......@@ -11,6 +11,6 @@
@interface CSBookmarksViewController : UIViewController
@property (nonatomic, strong) IBOutlet RMMapView *mapView;
@property (nonatomic, weak) IBOutlet MGLMapView *mapView;
@end
......@@ -9,9 +9,8 @@
#import "CSBookmarksViewController.h"
#pragma mark - CSViewController Private Interface
#pragma maek
@interface CSBookmarksViewController () <RMMapViewDelegate>
@interface CSBookmarksViewController () <MGLMapViewDelegate>
@end
......@@ -25,32 +24,32 @@
[super viewDidLoad];
CSAuthenticationManager *auth = [CSAuthenticationManager sharedManager];
[auth setCredentialsWithClientId:@"user"
clientSecret:@"pass"];
CSMapSource *source = [[CSMapSource alloc] initWithMapId:@"cedarmaps.streets"];
self.mapView.tileSource = source;
self.mapView.hideAttribution = YES;
self.mapView.showLogoBug = NO;
self.mapView.zoom = 16;
[auth setCredentialsWithClientID:@"clientID"
clientSecret:@"clientSecret"];
[self.mapView removeAllCachedImages];
CSMapKit *mapKit = [[CSMapKit alloc] initWithMapID:@"cedarmaps.streets"];
[mapKit styleURLWithCompletion:^(NSURL *url) {
dispatch_async(dispatch_get_main_queue(), ^{
self.mapView.styleURL = url;
});
}];
self.mapView.attributionButton.alpha = 0;
self.mapView.logoView.alpha = 0;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
/*
[self markBusStation];
[self markTrainStation];
[self markPointNumberOne];
[self markPointNumberTwo];
[self markPointNumberThree];
*/
self.mapView.centerCoordinate = CLLocationCoordinate2DMake(35.770889877650724, 51.439468860626214);
}
#pragma mark
......@@ -60,65 +59,62 @@
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://cedarmaps.com"]];
}
#pragma mark - RMMapViewDelegate Methods
- (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)annotation
{
if (annotation.isUserLocationAnnotation) {
return nil;
}
#pragma mark - MGLMapViewDelegate Methods
RMMarker *marker = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:annotation.userInfo]];
marker.anchorPoint = CGPointMake(1, 1);
marker.canShowCallout = YES;
- (MGLAnnotationImage *)mapView:(MGLMapView *)mapView imageForAnnotation:(id<MGLAnnotation>)annotation {
MGLAnnotationImage *image = [MGLAnnotationImage annotationImageWithImage:[UIImage imageNamed:annotation.subtitle] reuseIdentifier:annotation.subtitle];
return image;
}
return marker;
- (BOOL)mapView:(MGLMapView *)mapView annotationCanShowCallout:(id<MGLAnnotation>)annotation {
return YES;
}
#pragma mark -
- (void)markBusStation
{
RMAnnotation *annotation = [RMAnnotation annotationWithMapView:self.mapView
coordinate:CLLocationCoordinate2DMake(35.770889877650724, 51.439468860626214)
andTitle:@"ایستگاه اتوبوس"];
annotation.userInfo = @"bus_station";
MGLPointAnnotation *annotation = [[MGLPointAnnotation alloc] init];
annotation.coordinate = CLLocationCoordinate2DMake(35.770889877650724, 51.439468860626214);
annotation.title = @"ایستگاه اتوبوس";
annotation.subtitle = @"bus_station";
[self.mapView addAnnotation:annotation];
}
- (void)markTrainStation
{
RMAnnotation *annotation = [RMAnnotation annotationWithMapView:self.mapView
coordinate:CLLocationCoordinate2DMake(35.772857173873305, 51.437859535217285)
andTitle:@"مترو"];
annotation.userInfo = @"train_station";
MGLPointAnnotation *annotation = [[MGLPointAnnotation alloc] init];
annotation.coordinate = CLLocationCoordinate2DMake(35.772857173873305, 51.437859535217285);
annotation.title = @"مترو";
annotation.subtitle = @"train_station";
[self.mapView addAnnotation:annotation];
}
- (void)markPointNumberOne
{
RMAnnotation *annotation = [RMAnnotation annotationWithMapView:self.mapView
coordinate:CLLocationCoordinate2DMake(35.77633899479261, 51.4344048500061)
andTitle:@"نقطه اول"];
annotation.userInfo = @"point_one";
MGLPointAnnotation *annotation = [[MGLPointAnnotation alloc] init];
annotation.coordinate = CLLocationCoordinate2DMake(35.77633899479261, 51.4344048500061);
annotation.title = @"نقطه اول";
annotation.subtitle = @"point_one";
[self.mapView addAnnotation:annotation];
}
- (void)markPointNumberTwo
{
RMAnnotation *annotation = [RMAnnotation annotationWithMapView:self.mapView
coordinate:CLLocationCoordinate2DMake(35.77943768718256, 51.437666416168206)
andTitle:@"نقطه دوم"];
annotation.userInfo = @"point_two";
MGLPointAnnotation *annotation = [[MGLPointAnnotation alloc] init];
annotation.coordinate = CLLocationCoordinate2DMake(35.77943768718256, 51.437666416168206);
annotation.title = @"نقطه دوم";
annotation.subtitle = @"point_two";
[self.mapView addAnnotation:annotation];
}
- (void)markPointNumberThree
{
RMAnnotation *annotation = [RMAnnotation annotationWithMapView:self.mapView
coordinate:CLLocationCoordinate2DMake(35.77773168047123, 51.44279479980469)
andTitle:@"نقطه سوم"];
annotation.userInfo = @"point_three";
MGLPointAnnotation *annotation = [[MGLPointAnnotation alloc] init];
annotation.coordinate = CLLocationCoordinate2DMake(35.77773168047123, 51.44279479980469);
annotation.title = @"نقطه سوم";
annotation.subtitle = @"point_three";
[self.mapView addAnnotation:annotation];
}
......
......@@ -11,7 +11,7 @@
@interface CSSearchViewController : UIViewController <UITextFieldDelegate>
@property (nonatomic, weak) IBOutlet RMMapView *mapView;
@property (nonatomic, weak) IBOutlet MGLMapView *mapView;
@property (nonatomic, weak) IBOutlet UIView *searchView;
@property (nonatomic, weak) IBOutlet UIView *searchTextField;
@property (nonatomic, weak) IBOutlet UIActivityIndicatorView *spinner;
......
......@@ -11,9 +11,9 @@
#pragma mark - CSSearchViewController Private Interface
#pragma mark
@interface CSSearchViewController () <RMMapViewDelegate>
@interface CSSearchViewController () <MGLMapViewDelegate>
@property (nonatomic, strong) CSMapSource *mapSource;
@property (nonatomic, strong) CSMapKit *mapKit;
@end
......@@ -34,17 +34,17 @@
self.searchView.alpha = .95;
// Initializing map source
self.mapSource = [[CSMapSource alloc] initWithMapId:@"cedarmaps.streets"];
self.mapKit = [[CSMapKit alloc] initWithMapID:@"cedarmaps.streets"];
// Setting map view properties
self.mapView.tileSource = self.mapSource;
self.mapView.hideAttribution = YES;
self.mapView.showLogoBug = NO;
self.mapView.zoom = 16;
//[self.mapView removeAllCachedImages];
[self.mapKit styleURLWithCompletion:^(NSURL *url) {
dispatch_async(dispatch_get_main_queue(), ^{
self.mapView.styleURL = url;
});
}];
self.mapView.attributionButton.alpha = 0;
self.mapView.logoView.alpha = 0;
self.mapView.centerCoordinate = CLLocationCoordinate2DMake(35.757552763570196, 51.41000747680664);
}
- (void)viewDidAppear:(BOOL)animated
......@@ -75,62 +75,65 @@
return NO;
}
#pragma mark - RMMapViewDelegate Methods
- (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)annotation
{
if (annotation.isUserLocationAnnotation) {
return nil;
}
#pragma mark - MGLMapViewDelegate Methods
RMMarker *marker = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"star"]];
marker.anchorPoint = CGPointMake(1, 1);
marker.canShowCallout = YES;
- (MGLAnnotationImage *)mapView:(MGLMapView *)mapView imageForAnnotation:(id<MGLAnnotation>)annotation {
MGLAnnotationImage *image = [MGLAnnotationImage annotationImageWithImage:[UIImage imageNamed:@"star"] reuseIdentifier:@"marker"];
return image;
}
return marker;
- (BOOL)mapView:(MGLMapView *)mapView annotationCanShowCallout:(id<MGLAnnotation>)annotation {
return YES;
}
#pragma mark - Private Methods
- (void)searchWithQueryString:(NSString *)query
{
CSQueryParameters *params = [CSQueryParameters new];
[params addLocationWithLatitude:self.mapView.centerCoordinate.latitude longitude:self.mapView.centerCoordinate.longitude];
[self.mapSource forwardGeocodingWithQueryString:query parameters:params completion:^(NSArray *results, NSError *error) {
[self.spinner stopAnimating];
if (error != nil) {
[[[UIAlertView alloc] initWithTitle:@"بروز خطا"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"باشه"
otherButtonTitles:nil] show];
return;
}
[self.mapView removeAllAnnotations];
for (NSDictionary *item in results) {
NSArray *center = [[item objectForKey:@"location"][@"center"] componentsSeparatedByString:@","];
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake([center[0] doubleValue], [center[1] doubleValue]);
RMAnnotation *annotation = [RMAnnotation annotationWithMapView:self.mapView
coordinate:coordinate
andTitle:[item objectForKey:@"name"]];
annotation.userInfo = @"search_result";
[self.mapView addAnnotation:annotation];
}
if (results.count > 0) {
RMAnnotation *firstAnnotation = [self.mapView.annotations objectAtIndex:0];
[self.mapView setCenterCoordinate:firstAnnotation.coordinate animated:YES];
}
else {
[[[UIAlertView alloc] initWithTitle:@"جستجو بدون نتیجه"
message:@"مکان مورد نظر پیدا نشد."
delegate:nil
cancelButtonTitle:@"باشه"
otherButtonTitles:nil] show];
}
CSQueryParameters *params = [[CSQueryParameters alloc] init];
[params addLocationWithCoordinate:self.mapView.centerCoordinate];
[params addDistance:10.0];
[self.mapKit forwardGeocodingWithQueryString:query parameters:params completion:^(NSArray *results, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.spinner stopAnimating];
if (error != nil) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"بروز خطا" message:error.localizedDescription preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"باشه" style:UIAlertActionStyleCancel handler:NULL]];
[self presentViewController:alert animated:YES completion:NULL];
return;
}
if (self.mapView.annotations && self.mapView.annotations.count > 0) {
[self.mapView removeAnnotations:self.mapView.annotations];
}
for (NSDictionary *item in results) {
NSArray *center = [[item objectForKey:@"location"][@"center"] componentsSeparatedByString:@","];
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake([center[0] doubleValue], [center[1] doubleValue]);
MGLPointAnnotation *annotation = [[MGLPointAnnotation alloc] init];
annotation.coordinate = coordinate;
annotation.title = [item objectForKey:@"name"];
[self.mapView addAnnotation:annotation];
}
if (results.count > 0) {
MGLPointAnnotation *firstAnnotation = self.mapView.annotations.firstObject;
[self.mapView setCenterCoordinate:firstAnnotation.coordinate animated:YES];
}
else {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"جستجو بدون نتیجه" message:@"مکان مورد نظر پیدا نشد." preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"باشه" style:UIAlertActionStyleCancel handler:NULL]];
[self presentViewController:alert animated:YES completion:NULL];
}
});
}];
}
......
......@@ -29,6 +29,8 @@
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Maps Needs Location</string>
<key>UIMainStoryboardFile</key>
<string>Main_iPhone</string>
<key>UIMainStoryboardFile~ipad</key>
......
......@@ -2,6 +2,16 @@
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
......@@ -33,6 +43,16 @@
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
......
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
target 'CedarMaps' do
pod 'CedarMaps'
end
This diff is collapsed.
......@@ -2,9 +2,6 @@
<Workspace
version = "1.0">
<FileRef
location = "group:CedarMaps.xcodeproj">
</FileRef>
<FileRef
location = "group:Pods/Pods.xcodeproj">
location = "self:Example_Swift.xcodeproj">
</FileRef>
</Workspace>
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "App Icon 120x120.png",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"extent" : "full-screen",
"idiom" : "iphone",
"subtype" : "736h",
"filename" : "Portrait---6-Plus.png",
"minimum-system-version" : "8.0",
"orientation" : "portrait",
"scale" : "3x"
},
{
"orientation" : "landscape",
"idiom" : "iphone",
"extent" : "full-screen",
"minimum-system-version" : "8.0",
"subtype" : "736h",
"scale" : "3x"
},
{
"extent" : "full-screen",
"idiom" : "iphone",
"subtype" : "667h",
"filename" : "Portrait---6.png",
"minimum-system-version" : "8.0",
"orientation" : "portrait",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"filename" : "Portrait---4.png",
"scale" : "2x"
},
{
"extent" : "full-screen",
"idiom" : "iphone",
"subtype" : "retina4",
"filename" : "Portrait---5.png",
"minimum-system-version" : "7.0",
"orientation" : "portrait",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "1x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "1x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"extent" : "full-screen",
"scale" : "1x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"extent" : "full-screen",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"extent" : "full-screen",
"subtype" : "retina4",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "to-status-bar",
"scale" : "1x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "full-screen",
"scale" : "1x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "to-status-bar",
"scale" : "1x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "full-screen",
"scale" : "1x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "to-status-bar",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "full-screen",
"scale" : "2x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "to-status-bar",
"scale" : "2x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "full-screen",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "cedarmaps-attribution.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "cedarmaps-attribution@2x.png"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "bus-stop.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "bus-stop@2x.png"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "1.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "1@2x.png"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "3.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "3@2x.png"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "2.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "2@2x.png"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "star.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "star@2x.png"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "metro.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "metro@2x.png"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
//
// AppDelegate.swift
// Example_Swift
//
// Created by Saeed Taheri on 2016/10/25.
// Copyright © 2016 Cedar Studios. All rights reserved.
//
import UIKit
@UIApplicationMain
class CSAppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
//
// ViewController.swift
// Example_Swift
//
// Created by Saeed Taheri on 2016/10/25.
// Copyright © 2016 Cedar Studios. All rights reserved.
//
import UIKit
import CedarMaps
class CSBookmarksViewController: UIViewController {
@IBOutlet weak var mapView: MGLMapView!
override func viewDidLoad() {
super.viewDidLoad()
let auth = CSAuthenticationManager.shared()
auth?.setCredentialsWithClientID("clientID", clientSecret: "clientSecret")
let mapKit = CSMapKit(mapID: "cedarmaps.streets")
mapKit?.styleURL(completion: { (url) in
DispatchQueue.main.async {
self.mapView.styleURL = url
}
})
mapView.attributionButton.alpha = 0
mapView.logoView.alpha = 0
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
markBusStation()
markTrainStation()
markPointNumberOne()
markPointNumberTwo()
markPointNumberThree()
}
@IBAction func attributionDidTouchUpInside(_ sender: UIButton?) {
UIApplication.shared.openURL(URL(string: "http://cedarmaps.com")!)
}
}
extension CSBookmarksViewController: MGLMapViewDelegate {
func mapView(_ mapView: MGLMapView, imageFor annotation: MGLAnnotation) -> MGLAnnotationImage? {
let image = MGLAnnotationImage(image: UIImage(named: annotation.subtitle!!)!, reuseIdentifier: annotation.subtitle!!)
return image
}
func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
return true
}
fileprivate func markBusStation() {
let annotation = MGLPointAnnotation()
annotation.coordinate = CLLocationCoordinate2DMake(35.770889877650724, 51.439468860626214)
annotation.title = "ایستگاه اتوبوس"
annotation.subtitle = "bus_station"
mapView.addAnnotation(annotation)
}
fileprivate func markTrainStation() {
let annotation = MGLPointAnnotation()
annotation.coordinate = CLLocationCoordinate2DMake(35.772857173873305, 51.437859535217285)
annotation.title = "مترو"
annotation.subtitle = "train_station"
mapView.addAnnotation(annotation)
}
fileprivate func markPointNumberOne() {
let annotation = MGLPointAnnotation()
annotation.coordinate = CLLocationCoordinate2DMake(35.77633899479261, 51.4344048500061)
annotation.title = "نقطه اول"
annotation.subtitle = "point_one"
mapView.addAnnotation(annotation)
}
fileprivate func markPointNumberTwo() {
let annotation = MGLPointAnnotation()
annotation.coordinate = CLLocationCoordinate2DMake(35.77943768718256, 51.437666416168206)
annotation.title = "نقطه دوم"
annotation.subtitle = "point_two"
mapView.addAnnotation(annotation)
}
fileprivate func markPointNumberThree() {
let annotation = MGLPointAnnotation()
annotation.coordinate = CLLocationCoordinate2DMake(35.77773168047123, 51.44279479980469)
annotation.title = "نقطه سوم"
annotation.subtitle = "point_three"
mapView.addAnnotation(annotation)
}
}
//
// CSSearchViewController.swift
// Example_Swift
//
// Created by Saeed Taheri on 2016/10/25.
// Copyright © 2016 Cedar Studios. All rights reserved.
//
import UIKit
import CedarMaps
class CSSearchViewController: UIViewController {
@IBOutlet weak var mapView: MGLMapView!
@IBOutlet weak var searchView: UIView!
@IBOutlet weak var searchTextField: UIView!
@IBOutlet weak var spinner: UIActivityIndicatorView!
fileprivate var mapKit = CSMapKit(mapID: "cedarmaps.streets")
override func viewDidLoad() {
super.viewDidLoad()
// Customizing search view and textfield
searchView.layer.shadowOffset = CGSize(width: 0.0, height: 1.0)
searchView.layer.shadowOpacity = 0.3
searchView.layer.shadowRadius = 1.5
searchView.layer.cornerRadius = 2
searchView.alpha = 0.95
mapKit?.styleURL(completion: { (url) in
DispatchQueue.main.async {
self.mapView.styleURL = url
}
})
mapView.attributionButton.alpha = 0
mapView.logoView.alpha = 0
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if mapView.annotations?.count == 0 {
searchTextField.becomeFirstResponder()
}
}
@IBAction func attributionDidTouchUpInside(_ sender: UIButton?) {
UIApplication.shared.openURL(URL(string: "http://cedarmaps.com")!)
}
fileprivate func search(with query: String?) {
guard let query = query else { return }
let params = CSQueryParameters()
params.addLocation(with: mapView.centerCoordinate)
params.addDistance(10.0)
mapKit?.forwardGeocoding(withQueryString: query, parameters: params, completion: { (results, error) in
DispatchQueue.main.async {
self.spinner.stopAnimating()
if error != nil {
let alert = UIAlertController(title: "بروز خطا", message: error?.localizedDescription ?? " ", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "باشه", style: .cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
return
}
if let annotations = self.mapView.annotations, annotations.count > 0 {
self.mapView.removeAnnotations(annotations)
}
for item in results! where item is NSDictionary {
let itemDic = item as! NSDictionary
if let center = ((itemDic.object(forKey: "location") as? NSDictionary)?.object(forKey: "center") as? String)?.components(separatedBy: ","), center.count == 2 {
let coordinate = CLLocationCoordinate2DMake(Double(center[0])!, Double(center[1])!)
let annotation = MGLPointAnnotation()
annotation.coordinate = coordinate
annotation.title = itemDic.object(forKey: "name") as? String
self.mapView.addAnnotation(annotation)
}
}
if results!.count > 0 {
if let firstAnnotation = self.mapView.annotations?.first {
self.mapView.setCenter(firstAnnotation.coordinate, animated: true)
}
} else {
let alert = UIAlertController(title: "جستجو بدون نتیجه", message: "مکان مورد نظر پیدا نشد.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "باشه", style: .cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
return
}
}
})
}
}
extension CSSearchViewController: UITextFieldDelegate {
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
spinner.startAnimating()
textField.resignFirstResponder()
search(with: textField.text)
return false
}
}
extension CSSearchViewController: MGLMapViewDelegate {
func mapView(_ mapView: MGLMapView, imageFor annotation: MGLAnnotation) -> MGLAnnotationImage? {
let image = MGLAnnotationImage(image: UIImage(named: "star")!, reuseIdentifier: "marker")
return image
}
func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
return true
}
}
......@@ -5,18 +5,41 @@
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main_iPhone</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Maps Needs Location</string>
</dict>
</plist>
This diff is collapsed.
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
target Example_Swift do
pod 'CedarMaps'
end
......@@ -10,16 +10,16 @@
@interface CSAuthenticationManager : NSObject
@property (nonatomic, copy, readonly) NSString *clientId;
@property (nonatomic, copy, readonly) NSString *clientID;
@property (nonatomic, copy, readonly) NSString *clientSecret;
@property (nonatomic, copy, readonly) NSString *accessToken;
@property (nonatomic, copy) NSString *baseURL;
- (void)setCredentialsWithClientId:(NSString *)clientId clientSecret:(NSString *)clientSecret;
- (void)requestAccessToken:(NSError *__autoreleasing *)error;
- (void)invalidateCredential;
+ (CSAuthenticationManager *)sharedManager;
- (void)setCredentialsWithClientID:(NSString *)clientID clientSecret:(NSString *)clientSecret;
- (void)requestAccessTokenFromServer:(void (^)(NSString *token, NSError *error))completion;
- (void)savedAccessToken:(void (^) (NSString *token))completion;
- (void)invalidateCredential;
@end
......@@ -11,9 +11,9 @@
static NSString * const kBaseURL = @"http://api.cedarmaps.com/v1";
static NSString * const kCurrentAccessToken = @"CedarMapsSDKUserAccessToken_v1";
@interface CSAuthenticationManager () {
NSString *_accessToken;
}
@interface CSAuthenticationManager ()
@property (nonatomic, strong) NSString *accessToken;
@end
......@@ -29,35 +29,37 @@ static NSString * const kCurrentAccessToken = @"CedarMapsSDKUserAccessToken_v1";
return self;
}
- (NSString *)accessToken
{
if (_accessToken == nil) {
- (void)savedAccessToken:(void (^) (NSString *token))completion {
if (!_accessToken) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
_accessToken = [defaults objectForKey:kCurrentAccessToken];
if (_accessToken == nil) {
[self requestAccessToken:nil];
if (!_accessToken) {
[self requestAccessTokenFromServer:^(NSString *token, NSError *error) {
completion(token);
}];
} else {
completion(_accessToken);
}
} else {
completion(_accessToken);
}
return _accessToken;
}
- (void)setCredentialsWithClientId:(NSString *)clientId clientSecret:(NSString *)clientSecret
- (void)setCredentialsWithClientID:(NSString *)clientID clientSecret:(NSString *)clientSecret
{
NSAssert(clientId != nil && clientId.length > 0, @"Given Client ID is not in acceptable format.");
NSAssert(clientID != nil && clientID.length > 0, @"Given Client ID is not in acceptable format.");
NSAssert(clientSecret != nil && clientSecret.length > 0, @"Given Client Secret is not in acceptable format.");
_clientId = clientId;
_clientID = clientID;
_clientSecret = clientSecret;
}
- (void)requestAccessToken:(NSError *__autoreleasing *)error
- (void)requestAccessTokenFromServer:(void (^)(NSString *token, NSError *error))completion
{
NSAssert(self.clientId != nil, @"No client id specified. Set your given credentials before trying to get an access token.");
NSAssert(self.clientSecret != nil, @"No client Secret specified. Set your given credentials before trying to get an access token.");
NSAssert(self.clientID != nil, @"No client id specified. Set your given credentials before trying to get an access token.");
NSAssert(self.clientSecret != nil, @"No client Secret specified. Set your given credentials before trying to get an access token.");
NSString *params = [NSString stringWithFormat:@"client_id=%@&client_secret=%@", self.clientId, self.clientSecret];
NSString *params = [NSString stringWithFormat:@"client_id=%@&client_secret=%@", self.clientID, self.clientSecret];
params = [params stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *tokenURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@/token", self.baseURL]];
......@@ -65,27 +67,34 @@ static NSString * const kCurrentAccessToken = @"CedarMapsSDKUserAccessToken_v1";
[request setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPMethod:@"POST"];
NSError *responseError = nil;
NSHTTPURLResponse *response = nil;
NSData *token = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&responseError];
if (response.statusCode == 200) {
NSError *serializationError = nil;
NSDictionary *result = [NSJSONSerialization JSONObjectWithData:token options:0 error:&serializationError];
if (serializationError != nil && error != nil) {
*error = serializationError;
[[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable token, NSURLResponse * _Nullable response, NSError * _Nullable responseError) {
if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode];
if (statusCode == 200) {
NSError *serializationError;
NSDictionary *result = [NSJSONSerialization JSONObjectWithData:token options:0 error:&serializationError];
if (serializationError != nil) {
completion(nil, serializationError);
return;
}
_accessToken = result[@"access_token"];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:_accessToken forKey:kCurrentAccessToken];
completion(_accessToken, nil);
return;
} else if (responseError != nil) {
completion(nil, responseError);
return;
}
} else if (responseError != nil) {
completion(nil, responseError);
return;
}
_accessToken = result[@"access_token"];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:_accessToken forKey:kCurrentAccessToken];
[defaults synchronize];
}
else if (responseError != nil && error != nil) {
*error = responseError;
}
}] resume];
}
- (void)invalidateCredential
......
//
// CSMapSource.h
// CSMapStyle.h
// Pods
//
// Created by Emad A. on 30/01/2015.
//
//
#import "Mapbox.h"
@import CoreLocation;
@class CSQueryParameters;
/* An CSMapSource is used to display map tiles from a network-based map hosted on Cedar Map.
* Map should be referenced by their map ID.
/* A CSMapKit is used to display map tiles from a network-based map hosted on CedarMaps as well as getting geocoding data from server.
* Maps should be referenced by their map ID.
*/
@interface CSMapSource : RMAbstractWebMapSource
@interface CSMapKit: NSObject
@property (nonatomic, copy, readonly) NSString *mapId;
@property (nonatomic, copy, readonly) NSString *mapID;
@property (nonatomic, readonly) NSString *version;
@property (nonatomic, readonly) RMSphericalTrapezium bounds;
- (id)initWithMapId:(NSString *)mapId;
- (id)initWithMapId:(NSString *)mapId enablingDataOnMapView:(RMMapView *)mapView;
- (instancetype)initWithMapID:(NSString *)mapID;
- (void)styleURLWithCompletion:(void (^) (NSURL *url))completion;
- (void)forwardGeocodingWithQueryString:(NSString *)query
parameters:(CSQueryParameters *)parameters
completion:(void (^)(NSArray *results, NSError *error))completion;
......@@ -37,9 +34,7 @@
- (void)addCity:(NSString *)city;
- (void)addLimit:(NSUInteger)limit;
- (void)addDistance:(CGFloat)distance;
- (void)addLocationWithLatitude:(CGFloat)latitude longitude:(CGFloat)longitude;
- (void)addDistance:(CLLocationDistance)distance;
- (void)addLocationWithCoordinate:(CLLocationCoordinate2D)coordinate;
@end
#define CSMapSourceErrorNotification @"CSMapSourceErrorNotification"
\ No newline at end of file
//
// CSMapStyle.m
// Pods
//
// Created by Emad A. on 30/01/2015.
//
//
#import "CSMapKit.h"
#import "CSAuthenticationManager.h"
#define HTTP_404_NOT_FOUND 404
#define HTTP_401_NOT_AUTHORIZED 401
#define TOKEN_NOT_PROVIDED @"Token is not provided"
#define TOKEN_NOT_PROVIDED_CODE -68
#define INVALID_CREDINTIAL @"Invalid credential"
#pragma mark - CSQueryParameters Private Interface
@interface CSQueryParameters ()
@property (nonatomic, strong) NSMutableDictionary *params;
@end
#pragma mark - CSMapSource Private Interface
@interface CSMapKit ()
@property (nonatomic, copy) NSString *mapID;
@end
#pragma mark - CSMapSource Implementation
@implementation CSMapKit
- (instancetype)initWithMapID:(NSString *)mapID
{
self = [super init];
if (self != nil) {
self.mapID = mapID;
}
return self;
}
#pragma mark StyleURL
- (void)styleURLWithCompletion:(void (^) (NSURL *url))completion {
[[CSAuthenticationManager sharedManager] savedAccessToken:^(NSString *token) {
NSString *tileJSONURLString = [NSString stringWithFormat:@"%@/styles/%@.json", [[CSAuthenticationManager sharedManager] baseURL] , self.mapID];
if (token && token.length > 0) {
tileJSONURLString = [tileJSONURLString stringByAppendingFormat:@"?access_token=%@", token];
completion([NSURL URLWithString:tileJSONURLString]);
} else {
completion(nil);
}
}];
}
#pragma mark Geocoding
- (void)forwardGeocodingWithQueryString:(NSString *)query
parameters:(CSQueryParameters *)parameters
completion:(void (^)(NSArray *results, NSError *error))completion
{
NSMutableString *URLString = [NSMutableString stringWithFormat:@"%@/geocode/%@/%@", [[CSAuthenticationManager sharedManager] baseURL], self.mapID, query];
if (parameters != nil) {
[URLString appendString:@"?"];
[parameters.params enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
if (key > 0) {
[URLString appendString:@"&"];
}
[URLString appendFormat:@"%@=%@", key, obj];
}];
}
NSURL *URL = [NSURL URLWithString:[URLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
[[CSAuthenticationManager sharedManager] savedAccessToken:^(NSString *token) {
if (token) {
[request setValue:[NSString stringWithFormat:@"Bearer %@", token] forHTTPHeaderField:@"Authorization"];
[[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if ([(NSHTTPURLResponse *)response statusCode] == HTTP_401_NOT_AUTHORIZED) {
NSString *description = NSLocalizedString(INVALID_CREDINTIAL, @"");
NSError *responseError = [NSError errorWithDomain:NSCocoaErrorDomain code:kCFURLErrorUserCancelledAuthentication userInfo:@{NSLocalizedDescriptionKey: description}];
completion(nil, responseError);
} else {
if (error != nil) {
completion(nil, error);
} else {
NSError *serializationError;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&serializationError];
if (serializationError == nil) {
NSArray *output = [NSArray array];
if ([json.allKeys containsObject:@"results"]) {
NSArray *results = [json objectForKey:@"results"];
output = results;
}
completion(output, nil);
}
else {
completion(nil, serializationError);
}
}
}
}] resume];
} else {
NSString *description = NSLocalizedString(TOKEN_NOT_PROVIDED, @"");
NSError *error = [[NSError alloc] initWithDomain:NSCocoaErrorDomain code:TOKEN_NOT_PROVIDED_CODE userInfo:@{NSLocalizedDescriptionKey: description}];
completion(nil, error);
}
}];
}
- (void)reverseGeocodingWithCoordinate:(CLLocationCoordinate2D)coordinate
completion:(void (^)(NSDictionary *results, NSError *error))completion
{
NSMutableString *URLString = [NSMutableString stringWithFormat:@"%@/geocode/%@/%@,%@.json",
[[CSAuthenticationManager sharedManager] baseURL], self.mapID, @(coordinate.latitude), @(coordinate.longitude)];
NSURL *URL = [NSURL URLWithString:[URLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
[[CSAuthenticationManager sharedManager] savedAccessToken:^(NSString *token) {
if (token) {
[request setValue:[NSString stringWithFormat:@"Bearer %@", token] forHTTPHeaderField:@"Authorization"];
[[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if ([(NSHTTPURLResponse *)response statusCode] == HTTP_401_NOT_AUTHORIZED) {
NSString *description = NSLocalizedString(INVALID_CREDINTIAL, @"");
NSError *responseError = [NSError errorWithDomain:NSCocoaErrorDomain code:kCFURLErrorUserCancelledAuthentication userInfo:@{NSLocalizedDescriptionKey: description}];
completion(nil, responseError);
} else {
if (error != nil) {
completion(nil, error);
} else {
NSError *serializationError;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&serializationError];
if (serializationError == nil) {
NSDictionary *output = [NSDictionary dictionary];
if ([json.allKeys containsObject:@"result"]) {
NSDictionary *result = [json objectForKey:@"result"];
output = result;
}
}
else {
completion(nil, serializationError);
}
}
}
}] resume];
} else {
NSString *description = NSLocalizedString(TOKEN_NOT_PROVIDED, @"");
NSError *error = [[NSError alloc] initWithDomain:NSCocoaErrorDomain code:TOKEN_NOT_PROVIDED_CODE userInfo:@{NSLocalizedDescriptionKey: description}];
completion(nil, error);
}
}];
}
@end
#pragma mark
@implementation CSQueryParameters
- (id)init
{
self = [super init];
if (self != nil) {
self.params = [NSMutableDictionary dictionary];
}
return self;
}
- (void)addCity:(NSString *)city
{
[self.params setObject:city forKey:@"city"];
}
- (void)addLimit:(NSUInteger)limit
{
[self.params setObject:@(limit) forKey:@"limit"];
}
- (void)addDistance:(CLLocationDistance)distance
{
[self.params setObject:@(distance) forKey:@"distance"];
}
- (void)addLocationWithCoordinate:(CLLocationCoordinate2D)coordinate
{
[self.params setObject:[NSString stringWithFormat:@"%@,%@", @(coordinate.latitude), @(coordinate.longitude)] forKey:@"location"];
}
@end
This diff is collapsed.
......@@ -6,7 +6,7 @@
//
//
#import "Mapbox.h"
@import Mapbox;
#import "CSMapSource.h"
#import "CSMapKit.h"
#import "CSAuthenticationManager.h"
......@@ -4,36 +4,42 @@
To run the example project, clone the repo, and run `pod install` from the Example directory first.
To use CedarStudio Map you need a pair of client ID and secret which is needed at the first step of initialising the SDK.
To use CedarStudio Maps you need a pair of client ID and secret which is needed at the first step of initialising the SDK.
CSAuthenticationManager *auth = [CSAuthenticationManager sharedManager];
[auth setCredentialsWithClientId:@“<your client Id>“ clientSecret:@“<your client secret>”];
[auth setCredentialsWithClientID:@"<your client Id>" clientSecret:@"<your client secret>"];
If your project has its own base URL which is not the one SDK provides, you can set that here:
auth.baseURL = @"http://api.myowncedarmaps.com/v1“;
Then an instance of CSMapSource should be initialised:
Then an instance of CSMapKit should be initialised:
CSMapSource *source = [[CSMapSource alloc] initWithMapId:@"cedarmaps.streets"];
CSMapKit *source = [[CSMapKit alloc] initWithMapID:@"cedarmaps.streets"];
``MapId`` actually is the style of will be shown by source and could be anything but at the moment the only accepted value is ``cedarmaps.streets``. We will add other values and style latter.
``MapID`` is the style that will be shown by source and could be anything but at the moment the only accepted value is ``cedarmaps.streets``. We will add other values and style later.
The map source instance will be used as tile source for a ``RMMapView``:
There is an asynchronous method in CSMapKit which provides you with ``styleURL``:
self.mapView.tileSource = source;
- (void)styleURLWithCompletion:(void (^) (NSURL *url))completion;
or initialised a ``CSMapSource`` with your instance of ``RMMapView``:
You then set the url as styleURL for ``MGLMapView``:
self.mapView.styleURL = url;
CSMapSource *source = [[CSMapSource alloc] initWithMapId:@"cedarmaps.streets" enablingDataOnMapView:self.mapView];
or initialise a ``MGLMapView`` with the url:
self.mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 300, 400) styleURL:url];
``CSMapSource`` has two methods for forward geocoding and reverse geocoding that returne a ``NSArray`` and ``NSDictionary`` respectively as soon as their job get done.
``CSMapKit`` has two methods for forward geocoding and reverse geocoding that return a ``NSArray`` and ``NSDictionary`` respectively as soon as their job gets done.
- (void)forwardGeocodingWithQueryString:(NSString *)query parameters:(CSQueryParameters *)parameters completion:(void (^)(NSArray *results, NSError *error))completion;
- (void)reverseGeocodingWithCoordinate:(CLLocationCoordinate2D)coordinate completion:(void (^)(NSDictionary *result, NSError *error))completion;
In case you have got a credential error with ``nil`` as the result, there might be something wrong with your credentials at server side. So, before retrying and sending the request again request a new access token by calling method ``- (void)requestAccessToken:(NSError *__autoreleasing *)error`` of ``CSAuthenticationManager`` class.
In case you have got a credential error with ``nil`` as the result, there might be something wrong with your credentials at server side. So, before retrying and sending the request again request a new access token by calling method ``- (void)requestAccessTokenFromServer:(void (^)(NSString *token, NSError *error))completion;`` of ``CSAuthenticationManager`` class.
Example projects for both ``Objective C`` and ``Swift`` are included.
## Requirements
......@@ -41,14 +47,16 @@ In case you have got a credential error with ``nil`` as the result, there might
## Installation
CedarMap is available through [CocoaPods](http://cocoapods.org). To install
CedarMaps is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:
pod "CedarMap"
pod 'CedarMaps'
## Author
CedarStudio ®
## License
CedarMap is available under the MIT license. See the LICENSE file for more info.
CedarMaps is available under the MIT license. See the LICENSE file for more info.
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