在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:watsonbox/ios_google_places_autocomplete开源软件地址:https://github.com/watsonbox/ios_google_places_autocomplete开源编程语言:Swift 83.3%开源软件介绍:GooglePlacesAutocompleteA simple Google Places API autocompleting address entry view for iOS devices. There are already a couple of solutions out there for this. GooglePlacesAutocomplete is different because it is 100% Swift, and aims to provide the simplest possible method of entering validated, autocompleted addresses. No attempt has been made to integrate MapKit since displaying Google Places on a non-Google map is against their terms of service. Requirements
Installation
CocoaPodsCocoaPods is a dependency manager for Cocoa projects. CocoaPods 0.36 adds supports for Swift and embedded frameworks. You can install it with the following command: $ gem install cocoapods To integrate GooglePlacesAutocomplete into your Xcode project using CocoaPods, specify it in your source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
pod 'GooglePlacesAutocomplete' Then, run the following command: $ pod install ManualSimply copy Note: Don't forget to add the PoweredByGoogle image to your xcassets. UsageUse the Google Developers Console to enabled the 'Google Places API Web Service' and create a 'Server' API key credential. In both cases do not use the iOS options. import GooglePlacesAutocomplete // Not required when including source files directly in project
let gpaViewController = GooglePlacesAutocomplete(
apiKey: "[YOUR GOOGLE PLACES API KEY]",
placeType: .Address
)
gpaViewController.placeDelegate = self // Conforms to GooglePlacesAutocompleteDelegate
presentViewController(gpaViewController, animated: true, completion: nil)
Here's a complete example. Place DetailsFrom Google's documentation: "you can request more details about a particular establishment or point of interest by initiating a Place Details request. A Place Details request returns more comprehensive information about the indicated place such as its complete address, phone number, user rating and reviews." place.getDetails { details in
println(details.name) // Convenience accessor for name
println(details.latitude) // Convenience accessor for latitude
println(details.longitude) // Convenience accessor for longitude
println(details.raw) // Complete JSON data (see below)
}
/*
[
status: OK,
result: {
"address_components" = (
{
"long_name" = Paris;
"short_name" = Paris;
types = (
locality,
political
);
},
...
);
geometry = {
location = {
lat = "48.856614";
lng = "2.3522219";
};
...
*/ See the documentation for full response details. Location BiasingThe Place Autocomplete API supports biasing results to a specified circle by passing a gpaViewController.locationBias = LocationBias(latitude: 48.8534275, longitude: 2.3582787999999937, radius: 1000) StylingThe UINavigationController appearance can also easily be changed, for example: gpaViewController.navigationBar.barStyle = UIBarStyle.Black
gpaViewController.navigationBar.translucent = false
gpaViewController.navigationBar.barTintColor = UIColor(red: 0.11, green: 0.27, blue: 0.53, alpha: 1.0)
gpaViewController.navigationBar.tintColor = UIColor.whiteColor()
gpaViewController.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "Zapfino", size: 16.0)!] Also, to change the contents of the title bar: gpaViewController.navigationItem.title = "Enter City"
gpaViewController.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Cancel, target: gpaViewController, action: "close") Contributing
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论