Google Places API:
Google Places API
suggest changePrerequisites
- Install pods in your project
- Install the GooglePlaces SDK
- Enable location services
First we need to get the users location by getting their current longitude and latitude.
- Import GooglePlaces and GooglePlacePicker
import GooglePlaces
import GooglePlacePicker
- Add the
CLLOcationManagerDelegateprotocol
class ViewController: UIViewController, CLLocationManagerDelegate {
}
- create your CLLocationManager()
var currentLocation = CLLocationManager()
- Request authorization
currentLocation = CLLocationManager()
currentLocation.requetAlwayAuthorization()
- Create a button to call the GooglePlacePicker method
@IBAction func placePickerAction(sender: AnyObject) {
if CLLOcationManager.authorizationStatues() == .AuthorizedAlways {
let center = CLLocationCoordinate2DMake((currentLocation.location?.coordinate.latitude)!, (currentLocation.location?.coordinate.longitude)!)
let northEast = CLLocationCoordinate2DMake(center.latitude + 0.001, center.longitude + 0.001)
let southWest = CLLocationCoordinate2DMake(center.latitude - 0.001, center.longitude - 0.001)
let viewport = GMSCoordinateBounds(coordinate: northEast, coordinate: southWest)
let config = GMSPlacePickerConfig(viewport: viewport)
placePicker = GMSPlacePicker(config: config)
placePicker?.pickPlaceWithCallback({ (place: GMSPlace?, error: NSError?) -> Void in
if let error = error {
print("Pick Place error: \(error.localizedDescription)")
return
}
if let place = place {
print("Place name: \(place.name)")
print("Address: \(place.formattedAddress)")
} else {
print("Place name: nil")
print("Address: nil")
}
})
}
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents
1
UILabel
5
UIButton
10
UITableView
11
Auto Layout
12
UIView
14
MKMapView
15
UIColor
17
CAAnimation
18
UITextView
20
Concurrency
25
UIStackView
26
UIImage
27
UIWebView
28
CALayer
30
NSDate
31
Custom Fonts
34
UIScrollView
35
Localization
37
UITextField
40
iBeacon
41
CLLocation
42
NSURLSession
43
UISwitch
47
PDF Creation
49
NSTimer
50
CGContext
55
FacebookSDK
56
AFNetworking
57
CTCallCenter
61
UIBezierPath
63
UIAppearance
67
Storyboard
69
Fastlane
70
CAShapeLayer
71
WKWebView
73
Categories
77
UIPickerView
78
Dynamic Type
79
NSURL
86
IBOutlets
87
AWS SDK
91
UIDevice
92
CloudKit
93
GameplayKit
96
NSData
98
Deep Linking
100
Core Graphics
101
Segues
102
UIDatePicker
103
NSPredicate
104
EventKit
105
NSBundle
106
SiriKit
110
NSURLConnection
111
StoreKit
112
Code signing
114
Resizing UIImage
117
3D Touch
119
Keychain
122
Block
123
Content Hugging
124
Google Places API
125
Navigation Bar
136
Graph Coreplot
138
FCM Messaging
140
Custom Keyboard
141
AirDrop
144
UISlider
145
Carthage
146
HealthKit
147
Core SpotLight
148
UI Testing
149
Core Motion
150
QR Code Scanner
151
plist
152
NSInvocation
155
AppDelegate
157
MVVM
158
UIStoryboard
161
MPVolumeView
164
UIPhoenix
166
Simulator
167
BackgroundModes
168
NSArray
169
OpenGL
172
MVP Architecture
173
UIKit Dynamics
175
Core Data
179
MyLayout
180
UIFont
181
Simulator Builds
189
Security
195
UITableViewCell
200
Codable
201
FileHandle
202
NSUserActivity
210
Contributors