I am using below code to filter country data and i got success. and I am working on Swift 2.3 in Xcode 8.0 .
let autocompleteController = GMSAutocompleteViewController()
autocompleteController.delegate = self
let filter = GMSAutocompleteFilter()
filter.type = .Address
filter.country = "US"
autocompleteController.autocompleteFilter = filter
self.presentViewController(autocompleteController, animated: true, completion: nil)
I want more.
1) I want to filter particular state data (Like, Michigan) in United State, so any idea how can I filter it. I had suffering internet at my best but i can not get it.
Wishing your reply
Get the geolocation of that specific location (in your case Michigan) and set a radius and apply strictBounds in the parameters section and it'll display only results within the region.
Related
Goal
I want to make my search box auto-complete detecting place name and address.
Currently, my search box auto-complete detecting only the address.
I used this one in my iOS app. Result is looking good for addresses but not place name.
https://github.com/shmidt/GooglePlacesSearchController
I want it to detect places, like B&H Photo in NYC and so on ?
Example what I'm trying to do
Is it a paid service that I need to enable on Google API Console Library ?
Can someone sheds some lights on this ?
Just change your GooglePlacesSearchController initialization parameter placeType to .noFilter
let controller = GooglePlacesSearchController(
delegate: self, apiKey: GoogleMapsAPIServerKey, placeType: .noFilter)
For anyone with the same question but different implementation , just add a filter to your GMSAutocompleteViewController
let autocompleteController = GMSAutocompleteViewController()
autocompleteController.delegate = self
// Specify a filter.
let filter = GMSAutocompleteFilter()
filter.type = .noFilter
autocompleteController.autocompleteFilter = filter
I'm using mapkit and able to get Address for a particular location
let firstPlacemark = placemarks,
let addressDictionary = firstPlacemark.addressDictionary else { return }
// let street = addressDictionary["Street"]
// let city = addressDictionary["City"]
// let state = addressDictionary["State"]
// let zip = addressDictionary["ZIP"]
print(addressDictionary.description)
if let array = addressDictionary["FormattedAddressLines"] as? [Any] {
let address = array.map { "\($0)" }.joined(separator: ",\n")
print("Address : \(address)")
}
But Can we get more information like reviews contact no. images etc. Like Apple Maps shows (Observe Screeenshot)
Is there any API available in iOS for this or it will be provided via TripAdvisor???
P.S: I don't want to Any Google API.
Dear down voters if don't know the answers then kindly don't waste my points. It's easy to downvote, but you never know how much efforts has been added to earn those points.
OR Kindly provide me solution or show me if question is duplicate.
You can use Tripadvisor API
https://developer-tripadvisor.com/content-api/documentation/
ex.
http://api.tripadvisor.com/api/partner/2.0/location/155507?key=YOURKEY
I have this code in Swift 3 to get backendless user so I can get his/her properties:
let whereClause = "objectId = '\(userId)'"
let query = BackendlessDataQuery()
query.whereClause = whereClause
let data = Backendless.sharedInstance().persistenceService.of(BackendlessUser.ofClass())
data?.find(query, response: { (result) in
let user = result?.data.first as! BackendlessUser
myLabel.text = user.getProperty("firstName") as! String
})
The code is working fine but my question is how to observe the property changes ? is there a way if the value of property firstName changed I can update my label automatically ?
The use-case you describe is not really as simple as it may seem, but it's definitely possible.
You can capture any changes in Users table by creating an afterUpdate event handler. From there you could publish a message to some dedicated channel in messaging service.
At the same time, your application should be subscribed to this same channel. This way you could update your UI when the appropriate message is received.
I see below code in iOS9Sampler to use Search API in iOS 9. It use both NSUserActivity and CSSearchableIndex. So I want to ask question:
When should use NSUserActivity, when should use CSSearchableIndex? I see it make same result when search in Spotlight.
Below code call every viewDidLoad of view controller. Is it correct? Or should it call only one time? How can I check to call one time?
NSUserActivity
let activityType = String(format: "%#.%#", uniqueIdentifier, domainIdentifier)
activity = NSUserActivity(activityType: activityType)
activity.title = "iOS-9-Sampler_NSUserActivity"
activity.keywords = Set<String>(arrayLiteral: "dog", "cat", "pig", "sheep")
activity.eligibleForSearch = true
activity.becomeCurrent()
Core Spotlight
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeImage as String)
attributeSet.title = "iOS-9-Sampler_CoreSpotlight"
attributeSet.contentDescription = "iOS-9-Sampler is a code example collection for new features of iOS 9."
attributeSet.keywords = ["dog", "cat", "bird", "fish"]
let image = UIImage(named: "m7")!
let data = UIImagePNGRepresentation(image)
attributeSet.thumbnailData = data
let searchableItem = CSSearchableItem(
uniqueIdentifier: uniqueIdentifier,
domainIdentifier: domainIdentifier,
attributeSet: attributeSet)
CSSearchableIndex.defaultSearchableIndex().indexSearchableItems([searchableItem]) { (error) -> Void in
if error != nil {
print("failed with error:\(error)\n")
}
else {
print("Indexed!\n")
}
}
The type of content you're indexing and how the user interacts with it will determine if it's appropriate to use NSUserActivity or CSSearchableItem.
This is explained in the App Search Programming Guide, and examples are provided for a couple different scenarios, so be sure to review this thoroughly. Some notes:
Use NSUserActivity to index items as users perform activities in
your app, such as visiting a navigation point or creating and viewing
content.
Use Core Spotlight to add app-specific content to the on-device
index, such as persistent user data - documents, photos, and other
types of content.
CSSearchableItem does not require the user visit the content,
unlike NSUserActivity.
CSSearchableItem is not publicly indexable, while NSUserActivity
is.
I created a small messenger app using Parse as my database in swift. I wanted each time any user sends a message only other users within 10 meter to get the notification. The app is working but the push notification is not. I did some research it looks like my code is similar to the one i found but still not working. Please help me. Thank you
var CurrentLocation : PFGeoPoint = PFGeoPoint(latitude: 44.6854, longitude: -73.873) // assume the current user is here
let userQuery = PFUser.query()
userQuery?.whereKey("Location", nearGeoPoint: CurrentLocation, withinMiles: 10.0)
let pushQuery = PFInstallation.query()
pushQuery?.whereKey("username", matchesQuery: userQuery!)
let push = PFPush()
push.setQuery(pushQuery)
push.setMessage(" New message")
push.sendPushInBackground()
Your problem is the line pushQuery?.whereKey("username", matchesQuery: userQuery!). According to the parse docs Warning: This only works where the key’s values are PFObjects or arrays of PFObjects. Read more here: https://parse.com/docs/osx/api/Classes/PFQuery.html#//api/name/whereKey:matchesQuery
Instead change it to chain the query by first performing the first query and then using the strings of the userIds for the second query which is performed inside the first's completionBlock.
Update
Also, just as a side note you are not abiding by the camel case rules of swift and also the rules set out by Parse. You should follow conventions. (See my code for the correct case for keys in Parse and variable names).
Example:
var currentLocation : PFGeoPoint = PFGeoPoint(latitude: 44.6854, longitude: -73.873) // assume the current user is here
let userQuery = PFUser.query()
userQuery?.whereKey("location", nearGeoPoint: currentLocation, withinMiles: 10.0) // Note I changed Location to location
userQuery?.findObjectsInBackground({ results, error in
let usernames = (results as! [PFObject]).map { $0.username }
let pushQuery = PFInstallation.query()
pushQuery?.whereKey("username", containedIn: usernames)
let push = PFPush()
push.setQuery(pushQuery)
push.setMessage("New message")
push.sendPushInBackground()
})
Also note that you may need to change your structure because the docs for PFInstallation.query note that you must use one of three query parameters and you are using none (you might have to save the installation object id to a field on the user. Then instead of making an array with username make an array with the installation object ids and query PFInstallation like that. However, this may still work so try it first, you never know.