Open ak9250 opened 6 years ago
@ak9250 Thanks for your interests. I make this app is to practice my skill to create the identical app on both Android and iOS. Although I have no plan to do further develop, you are welcome to contribute. I will review and accept your PR asap. Also, I followed this tutorial to create the Table View.
I was using the Place id through search api but cant it to work right now.
Do you mean "change the search location" is not working? Let me know if anything does not work as expected.
ok, thanks for making this app, I mean this by place id as i am trying to get all location place ids to pull up reviews for that location
see https://developers.google.com/places/ios-sdk/place-details
I look up the Json from the search API. There were multiple ids returned ("id", "place_id", "alt_ids"). Maybe you can try out each id with lookUpPlaceID methed to see if anyone work. Keep in mind that the usage limit for Places SDK iOS is 1,000 requests per day.
yes what I dont understand if place id will only show for one place and the search results will return multiple locations. So I will have to track each place id seperately and pull the ratings when clicked on the location marker?
On their documentation, Place IDs uniquely identify a place. They didn't mention a way to get multiple Place details from a search result.
So I will have to track each place id separately and pull the ratings when clicked on the location marker?
Yes, I'm thinking the same thing.
still have no way to figure out this yet, its very confusing even with the documentation, I think there is possible two api calls that need to be done and the parse the json of the place id.
@CHico-Lee would you be up for a skype session to go through the code and help me integrate this feature?
Sorry for my late reply, let me write up the steps to integrate this feature, so we can understand the issue better.
This is the code I parse the json:
This section of code will be loop multiple times to parse data for each Starbuck store.
So this block of code will only execute when Unwrapping geometry
and location
is not nil
.
It looks confusing when Unwrap Multiple Optionals with One If-Let
Recall from the Json result from the search API, in their example, the results
has a field name
:
"name" : "Rhythmboat Cruises",
My code to get the string value:
Since place_id
is on the same level as name
, you can use the similar way to get the place_id
.
This is the code to store data for a single Starbuck:
Then all the Store
objects get store into the array in class NearbyStarbucks
NearbyStarbucks
is a Singleton class to maintain the result.
In order to store the place_id
you will need to add a field in class Store and update the constructor signature:
init (name: String, vicinity: String, lat: Double, lng: Double, openNow: Bool?, placeId: String) {
Then you should be able to store the place_id
here:
There is multiple ways to show the ratings, just be creative. You can show the rating on the list or you can show it on the map as a tooltip.
Accessing the the place_id
is really easy:
NearbyStarbucks.sharedInstance.stores[indexOfStore].placeId
Let me know if any part is confusing.
@CHico-Lee Hey, thanks for the detailed reponse, I been busy last few days so havent had much time to work on it. I was ablle to add all the things expect for step 3 pull ratings
let lat = location["lat"] as! Double let lng = location["lng"] as! Double let placeid = result["placeid"] as! String var openNow : Bool? = nil if let opening = result["opening_hours"] as! NSDictionary?{ if let opened = opening["open_now"] as! Bool? { openNow = opened } } let newStore = Store(name: name, vicinity: vicinity, lat: lat, lng: lng, openNow: openNow, placeid: placeid) NearbyStarbucks.sharedInstance.stores += [newStore]
`class Store { //MARK: Properties var name: String var vicinity: String var lat: Double var lng: Double var openNow: Bool? var placeid: String
init (name: String, vicinity: String, lat: Double, lng: Double, openNow: Bool?, placeid: String) {
self.name = name
self.vicinity = vicinity
self.lat = lat
self.lng = lng
self.openNow = openNow
self.placeid = placeid
}
}`
sorry for the noob questions, I am not good as swift, just started working with it. How do i get indexofStore or should i just run a loop for the list length?
Your step 1 and 2 looks perfect. So it is time for Step 3.
indexofStore
is an element index for the stores
array in NearbyStarbucks
class.
If you want to display the ratings on the list, you will need to loop through every store on the list to pull all the ratings. This is more complex.
To get thing start on easy, I would recommend showing the ratings on the map in the tooltip.
Will show the the ratings below the address.
Here is the code it will run when you open the map. You will need to add some code in. https://github.com/CHico-Lee/Starbucks-Finder-iOS/blob/42674f5c44f68a56bf5fc3f8436c57ad24d8ace7/starbucksfinder/MapViewController.swift#L20-L30
Follow this guide to try pulling data.
Store
object will be passed from StoreTableViewController
to MapViewController
. So, your placeID can get from:
placeID = store.placeid
Try this out you should be able to get your ratings print out in Xcode output windows. Then you can add the ratings into the tooltip.
This is the code to print address in tooltip. https://github.com/CHico-Lee/Starbucks-Finder-iOS/blob/42674f5c44f68a56bf5fc3f8436c57ad24d8ace7/starbucksfinder/MapViewController.swift#L47
If you complete this, you can also try to print the rating in the list.
Sorry for the late reply, enjoy the happy coding:)
would be nice to see google ratings for each store that comes up. I can work on a PR to get this to show but it might take me a while to go through the codebase. I was using the Place id through search api but cant it to work right now. Great job on this app.