Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions ComtradeGramFinal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
0784C4DB2019196F000E942E /* UIImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0784C4DA2019196F000E942E /* UIImageView.swift */; };
90C2055B863CC46A8EC5F904 /* Pods_ComtradeGramFinalTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0DE6CDDB43799CA87D77C0B2 /* Pods_ComtradeGramFinalTests.framework */; };
B2DB6D372B1B2596201149ED /* Pods_ComtradeGramFinal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA36AD9161F49952F5BD6D08 /* Pods_ComtradeGramFinal.framework */; };
D146B64620337E350060983D /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D146B64520337E350060983D /* MapKit.framework */; };
EB1FCA11AEBC2E7CA61E80C9 /* Pods_ComtradeGramFinalUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5972BEBF5F29AFF33D431699 /* Pods_ComtradeGramFinalUITests.framework */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -76,6 +77,7 @@
9CAB271CD111DF6FF66E1E89 /* Pods-ComtradeGramFinal.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ComtradeGramFinal.release.xcconfig"; path = "Pods/Target Support Files/Pods-ComtradeGramFinal/Pods-ComtradeGramFinal.release.xcconfig"; sourceTree = "<group>"; };
A3A5C9D7385833C8A86AED69 /* Pods-ComtradeGramFinalUITests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ComtradeGramFinalUITests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ComtradeGramFinalUITests/Pods-ComtradeGramFinalUITests.debug.xcconfig"; sourceTree = "<group>"; };
C8497E9560F46BE726082DDE /* Pods-ComtradeGramFinalUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ComtradeGramFinalUITests.release.xcconfig"; path = "Pods/Target Support Files/Pods-ComtradeGramFinalUITests/Pods-ComtradeGramFinalUITests.release.xcconfig"; sourceTree = "<group>"; };
D146B64520337E350060983D /* MapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; };
DA36AD9161F49952F5BD6D08 /* Pods_ComtradeGramFinal.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ComtradeGramFinal.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

Expand All @@ -84,6 +86,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
D146B64620337E350060983D /* MapKit.framework in Frameworks */,
B2DB6D372B1B2596201149ED /* Pods_ComtradeGramFinal.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -201,6 +204,7 @@
6457A64ECC6A6717543B3257 /* Frameworks */ = {
isa = PBXGroup;
children = (
D146B64520337E350060983D /* MapKit.framework */,
DA36AD9161F49952F5BD6D08 /* Pods_ComtradeGramFinal.framework */,
0DE6CDDB43799CA87D77C0B2 /* Pods_ComtradeGramFinalTests.framework */,
5972BEBF5F29AFF33D431699 /* Pods_ComtradeGramFinalUITests.framework */,
Expand Down Expand Up @@ -679,7 +683,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 43E5B5CSA6;
DEVELOPMENT_TEAM = DHFN8WY7B6;
INFOPLIST_FILE = ComtradeGramFinal/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = Comtrade.ComtradeGramFinal;
Expand All @@ -695,7 +699,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 43E5B5CSA6;
DEVELOPMENT_TEAM = DHFN8WY7B6;
INFOPLIST_FILE = ComtradeGramFinal/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = Comtrade.ComtradeGramFinal;
Expand Down
225 changes: 220 additions & 5 deletions ComtradeGramFinal/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions ComtradeGramFinal/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,9 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Allow your Location</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Allow your Location</string>
</dict>
</plist>
140 changes: 135 additions & 5 deletions ComtradeGramFinal/ViewControllers/MapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,150 @@

import UIKit
import SwiftInstagram
import MapKit

class MapViewController: UIViewController {

class MapViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate {

var post: InstagramMedia?


@IBOutlet weak var mapView: MKMapView!
let distanceSpan: Double = 500
let postPin = MKPointAnnotation()

var locationManager: CLLocationManager?

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

locationManager = CLLocationManager()
locationManager!.delegate = self
locationManager!.desiredAccuracy = kCLLocationAccuracyBestForNavigation
locationManager!.requestAlwaysAuthorization()
locationManager!.distanceFilter = 50

self.mapView.showsUserLocation = true

if CLLocationManager.authorizationStatus() == .authorizedWhenInUse {
locationManager!.startUpdatingLocation()
} else {
locationManager!.requestWhenInUseAuthorization()
}

}


override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

self.updatePostLocation()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


func locationManager(_ manager: CLLocationManager, didStartMonitoringFor region: CLRegion) {

}

private func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {


switch status {
case .notDetermined:
print("NotDetermined")
case .restricted:
print("Restricted")
case .denied:
print("Denied")
case .authorizedAlways:
print("AuthorizedAlways")
case .authorizedWhenInUse:
print("AuthorizedWhenInUse")
locationManager!.startUpdatingLocation()
}
}


// present user location on map
// get post location latitude and longitude and present it's pointer
// add annotation view with title: postName and description


func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation { return nil }

var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "identifier") as? MKPinAnnotationView
if annotationView == nil {
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "identifier")
annotationView?.canShowCallout = true
// annotationView?.rightCalloutAccessoryView = UIButton(type: .infoLight)
} else {
annotationView?.annotation = annotation
}

return annotationView
}

func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if control == view.rightCalloutAccessoryView {
print("button tapped")
}
}


func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
let userLocation = locations[0] as! CLLocation

locationManager?.stopUpdatingLocation()

let location = CLLocationCoordinate2D(latitude: userLocation.coordinate.latitude, longitude: userLocation.coordinate.longitude)

let span = MKCoordinateSpanMake(1.0, 1.0)

let region = MKCoordinateRegion(center: location, span: span)

self.mapView.setRegion(region, animated: false)

}

func updatePostLocation() {
if let mapView = self.mapView {
let location = self.post?.location
let center = self.post?.location

if let center = center {
let region = MKCoordinateRegion(center: center.coordinates, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
mapView.setRegion(region, animated: true)
mapView.showsUserLocation = true

mapView.removeAnnotation(self.postPin)

//set region on the map
mapView.setRegion(region, animated: true)

if let coordinates = location?.coordinates {
postPin.coordinate = coordinates

// Add an annotation

postPin.title = self.post?.user.username
postPin.subtitle = self.post?.caption?.text

mapView.addAnnotation(postPin)
}
}
}
}

func locationManager(manager: CLLocationManager, didUpdateToLocation newLocation: CLLocation, fromLocation oldLocation: CLLocation) {
if let mapView = self.mapView {
let region = MKCoordinateRegionMakeWithDistance(newLocation.coordinate, self.distanceSpan, self.distanceSpan)
mapView.setRegion(region, animated: true)
mapView.showsUserLocation = true
}
}

}

1 change: 1 addition & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ target 'ComtradeGramFinal' do

pod 'SwiftInstagram', '~> 1.1.0'


target 'ComtradeGramFinalTests' do
inherit! :search_paths
# Pods for testing
Expand Down
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ DEPENDENCIES:
SPEC CHECKSUMS:
SwiftInstagram: 90d5c143d8ebe1c790e06a138b8da3c8f2a9ba16

PODFILE CHECKSUM: b26df78b569c81a8edc3c89e01e7f93a59d9e263
PODFILE CHECKSUM: 06c43a2e950450c1134aaf25922f6568b528dc0e

COCOAPODS: 1.3.1
COCOAPODS: 1.4.0
4 changes: 2 additions & 2 deletions Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading