Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Menu's detail page #9

Merged
merged 20 commits into from
Jun 27, 2015
Merged
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
158 changes: 158 additions & 0 deletions MapViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
//
// MapViewController.swift
// adam
//
// Created by ariyasuk-k on 6/24/15.
// Copyright (c) 2015 gobbl. All rights reserved.
//

import UIKit
import Alamofire
import SwiftyJSON

class MapViewController: UIViewController, GMSMapViewDelegate {

@IBOutlet weak var addressTextView: UITextView!
@IBAction func backToDetail(sender: AnyObject) {
self.performSegueWithIdentifier("backFromMapView", sender: self)
}

@IBOutlet weak var mapView: UIView!
var restaurant: Restaurant!

var gMap:GMSMapView!
var gCamera:GMSCameraPosition!
var destinationMarker:GMSMarker!
var steps:Array<JSON>!
var polyline:GMSPolyline!

var apiKey:String!

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.gMap.myLocationEnabled = true
self.gMap.addObserver(self, forKeyPath: "myLocation", options: .New, context: nil)
}

override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
self.gMap.removeObserver(self, forKeyPath: "myLocation")
}
override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.

if let path = NSBundle.mainBundle().pathForResource("APISetting", ofType: "plist") {
if let dict = NSDictionary(contentsOfFile: path) as? Dictionary<String, AnyObject> {
if let googleMapAPI = dict["GoogleDirection"] as? String{
self.apiKey = googleMapAPI
}
}
}

if restaurant != nil {

addressTextView.text = restaurant.address

let screenWidth = UIScreen.mainScreen().bounds.width
let screenHeight = UIScreen.mainScreen().bounds.height

self.gCamera = GMSCameraPosition.cameraWithLatitude(restaurant.location.coordinate.latitude,
longitude: restaurant.location.coordinate.longitude, zoom: 17)

self.gMap = GMSMapView.mapWithFrame(CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight), camera: self.gCamera)
self.gMap.myLocationEnabled = true
self.gMap.settings.myLocationButton = true
self.gMap.settings.compassButton = true
self.gMap.delegate = self

self.destinationMarker = GMSMarker()
self.destinationMarker.position = self.gCamera.target
self.destinationMarker.snippet = restaurant.name
self.destinationMarker.appearAnimation = kGMSMarkerAnimationPop
self.destinationMarker.map = self.gMap

self.mapView.addSubview(self.gMap)

}
}

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

// MARK: - Google Maps Delegate
func mapView(mapView: GMSMapView!, didTapMarker marker: GMSMarker!) -> Bool {
if let startLocation = self.gMap.myLocation {
fetchDirectionsFrom(startLocation.coordinate, to: self.destinationMarker.position, completion: { (optionalRoute) -> Void in

})
}

return true
}



/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/


// MARK: Observer

override func observeValueForKeyPath(keyPath: String, ofObject object: AnyObject, change: [NSObject : AnyObject], context: UnsafeMutablePointer<Void>) {

if keyPath == "myLocation" && object.isKindOfClass(GMSMapView) {

/*fetchDirectionsFrom(self.gMap.myLocation.coordinate, to: self.destinationMarker.position, completion: { (optionalRoute) -> Void in

})*/


}
}


func fetchDirectionsFrom(from: CLLocationCoordinate2D, to: CLLocationCoordinate2D, completion: ((String?) -> Void)) -> ()
{
let urlString = "https://maps.googleapis.com/maps/api/directions/json"
let parameters:[String:AnyObject] = [
"key" : self.apiKey,
"origin" : [String(stringInterpolationSegment: from.latitude),String(stringInterpolationSegment: from.longitude)],
"destination" : [String(stringInterpolationSegment: to.latitude),String(stringInterpolationSegment: to.longitude)],
"mode" : "walking"
]
UIApplication.sharedApplication().networkActivityIndicatorVisible = true

Alamofire.request(.GET, urlString, parameters: parameters, encoding: .URL).responseJSON{
(req, res, json, error) in
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
if error != nil {
println(error)
} else {

let myJSON = JSON(json!)
self.steps = myJSON["routes"][0]["legs"][0]["steps"].arrayValue

NSOperationQueue.mainQueue().addOperationWithBlock({ () -> Void in
if let encodePath = myJSON["routes"][0]["overview_polyline"]["points"].string {
var path:GMSPath = GMSPath(fromEncodedPath: encodePath)
self.polyline = GMSPolyline(path: path)
self.polyline.strokeWidth = 5
self.polyline.strokeColor = UIColor.blueColor()
self.polyline.map = self.gMap
}
})
}
}
}
}
16 changes: 16 additions & 0 deletions adam.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
objects = {

/* Begin PBXBuildFile section */
213997341B3907580027AB55 /* MenuDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213997331B3907580027AB55 /* MenuDetailViewController.swift */; };
2150F5011B0EFEE200AFDF5E /* ProfileViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2150F5001B0EFEE200AFDF5E /* ProfileViewController.swift */; };
21577E061B2E875000D4218F /* CurrencyConverter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21577E051B2E875000D4218F /* CurrencyConverter.swift */; };
21577E081B2E87DB00D4218F /* CurrencyList.plist in Resources */ = {isa = PBXBuildFile; fileRef = 21577E071B2E87DB00D4218F /* CurrencyList.plist */; };
21A29D341B3A6166009E0D0C /* MapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21A29D331B3A6166009E0D0C /* MapViewController.swift */; };
21AF14871B05FA0B00108190 /* RestaurantServerAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AF14861B05FA0B00108190 /* RestaurantServerAPI.swift */; };
21AF14891B0601C800108190 /* Restaurant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AF14881B0601C800108190 /* Restaurant.swift */; };
21BF4D171B099714001CDBC3 /* RestaurantCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21BF4D161B099714001CDBC3 /* RestaurantCache.swift */; };
Expand Down Expand Up @@ -55,10 +57,12 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
213997331B3907580027AB55 /* MenuDetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuDetailViewController.swift; sourceTree = "<group>"; };
2150F4FB1B0ED81C00AFDF5E /* Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Bridging-Header.h"; sourceTree = "<group>"; };
2150F5001B0EFEE200AFDF5E /* ProfileViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProfileViewController.swift; sourceTree = "<group>"; };
21577E051B2E875000D4218F /* CurrencyConverter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CurrencyConverter.swift; sourceTree = "<group>"; };
21577E071B2E87DB00D4218F /* CurrencyList.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = CurrencyList.plist; sourceTree = "<group>"; };
21A29D331B3A6166009E0D0C /* MapViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MapViewController.swift; path = ../MapViewController.swift; sourceTree = "<group>"; };
21AF14861B05FA0B00108190 /* RestaurantServerAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RestaurantServerAPI.swift; sourceTree = "<group>"; };
21AF14881B0601C800108190 /* Restaurant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Restaurant.swift; sourceTree = "<group>"; };
21BF4D161B099714001CDBC3 /* RestaurantCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RestaurantCache.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -137,6 +141,14 @@
name = Frameworks;
sourceTree = "<group>";
};
213997321B3907160027AB55 /* Menu Detail */ = {
isa = PBXGroup;
children = (
213997331B3907580027AB55 /* MenuDetailViewController.swift */,
);
name = "Menu Detail";
sourceTree = "<group>";
};
4730F9DECD23A478A1E3060B /* Pods */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -169,6 +181,7 @@
9656AD9B1AECC62800933A8E /* benri */ = {
isa = PBXGroup;
children = (
21A29D331B3A6166009E0D0C /* MapViewController.swift */,
96E377191B35981100229684 /* Localizable.strings */,
21D741271B21A9A9008A8EB5 /* DiscoverView.xib */,
96DA5A191AF28AAA0003E506 /* SVAPI */,
Expand Down Expand Up @@ -235,6 +248,7 @@
96DA5A131AF284A80003E506 /* Menu */ = {
isa = PBXGroup;
children = (
213997321B3907160027AB55 /* Menu Detail */,
96DA5A141AF284BB0003E506 /* Menu.swift */,
96DA5A161AF2850E0003E506 /* MenuCell.swift */,
21577E051B2E875000D4218F /* CurrencyConverter.swift */,
Expand Down Expand Up @@ -418,13 +432,15 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
213997341B3907580027AB55 /* MenuDetailViewController.swift in Sources */,
964690861B3308D800DB187D /* TutorialViewController.swift in Sources */,
21AF14891B0601C800108190 /* Restaurant.swift in Sources */,
967867701B2C9A7F0047C7BB /* SearchCell.swift in Sources */,
9656ADA31AECC62800933A8E /* SecondViewController.swift in Sources */,
96DA5A0F1AF274670003E506 /* Const.swift in Sources */,
21BF4D171B099714001CDBC3 /* RestaurantCache.swift in Sources */,
96DA5A171AF2850E0003E506 /* MenuCell.swift in Sources */,
21A29D341B3A6166009E0D0C /* MapViewController.swift in Sources */,
96DA5A151AF284BB0003E506 /* Menu.swift in Sources */,
9656AD9F1AECC62800933A8E /* AppDelegate.swift in Sources */,
9646908A1B3392F600DB187D /* PageContentViewController.swift in Sources */,
Expand Down
Loading