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
Related
I'm relatively new to iOS and Mapbox development. I'm working on an app where a user can freely manipulate a map full of places they have saved.
When they reach a zoom-level that is completely filled by the geography of a city, I would like to display the name of the city which they are viewing in a banner-style view, even if a city label is not within view on the map (as is often the case when zoomed in).
Here's a screenshot of the UI for context.
I'm trying to query the Mapbox tileset for the city name using the following code:
func mapViewRegionIsChanging(_ mapView: MGLMapView) {
let zoomLevel = mapView.zoomLevel
if zoomLevel >= 14.0 {
// layer identifier taken from layer name in Mapbox Studio
let layerIdentifier = "place-city-lg-n"
let screenRect = UIScreen.main.bounds
let cityName = mapView.visibleFeatures(in: screenRect, styleLayerIdentifiers: Set([layerIdentifier]))
print(cityName)
}
I think this code doesn't work because the label is not onscreen at the specified zoom level.
I'm wondering if using visibleFeaturesInRect is the best approach for my needโis there a better way to retrieve city name regardless of visible elements and zoom level?
For this task I'd recommend using MapboxGeocoder from Mapbox. It is for getting information about the city/village.
you can install pod:
pod 'MapboxGeocoder.swift', '~> 0.12'
and use this code:
let geocoder = Geocoder.shared
func mapViewRegionIsChanging(_ mapView: MGLMapView) {
let geocodeOptions = ReverseGeocodeOptions(coordinate: mapView.centerCoordinate)
geocodeOptions.allowedScopes = [.place]
let _ = geocoder.geocode(geocodeOptions) { (placemarks, attribution, error) in
guard let placemark = placemarks?.first else { return }
print(placemark.name)
print(placemark.qualifiedName)
}
}
you can add your conditions and it really helps to solve your task
This is my first time using Uber api. I followed the instructions clearly, but it never really mentioned how to display price estimate in the button. My code magically displays the time( dunno why or how). Please explain how to display price as well. Both server token and client ID have been integrated in the info.plist file.
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let button = RideRequestButton()
view.addSubview(button)
button.center = view.center
let ridesClient = RidesClient()
let dropOffLocation = CLLocation(latitude: 20.301647, longitude: 85.819135)
let pickUpLocation = CLLocation(latitude : 20.323706, longitude: 85.814981)
let builder = RideParametersBuilder()
builder.pickupLocation = pickUpLocation
builder.pickupNickname = "Home"
builder.dropoffLocation = dropOffLocation
builder.dropoffNickname = "Mayfair Lagoon, Bhubaneswar"
var productID = ""
ridesClient.fetchProducts(pickupLocation: pickUpLocation) { (product, response) in
productID = product[1].productID
print("๐ฅ\(productID)")
}
ridesClient.fetchPriceEstimates(pickupLocation: pickUpLocation, dropoffLocation: dropOffLocation) { (price, response) in
print(price[0].estimate!,"๐")
}
ridesClient.fetchTimeEstimates(pickupLocation: pickUpLocation) { (time, response) in
print("๐ฅ",time[0].estimate,"๐ฅ")
}
builder.productID = productID
button.setContent()
button.rideParameters = builder.build()
button.loadRideInformation()
}
}
Button will Deeplink into the Uber App and will simply open up the app. In order to see real-time fare estimates and pickup ETA information you will need to pass additional parameters to it. The Ride Request Button can accept optional parameters to pre-load some information into the ride request. You can see how to do it in the Uber documentation. Also this is explained here on the GitHub
Please, check out StackOverflow thread here.
It is explained and documented how to manage this issue.
Please check it out below link
Display ETA and estimated money option for my "Ride there with Uber" button
I posted this issue on GitHub, though it has been over a week and no response from the developers, so hoping to get an answer here.
Using the example code, plus adding a bit to show placemarks returned from ForwardGeocodeOptions, I came up with this testing code:
(Swift 3, Xcode 8)
func mapView(_ mapView: MGLMapView, regionDidChangeAnimated animated: Bool) {
geocodingDataTask?.cancel()
self.outputText.text = ""
// Variables.userLat and Variables.userLng are set through locationManager
let options = ReverseGeocodeOptions(coordinate: CLLocationCoordinate2D(latitude: Variables.userLat, longitude: Variables.userLng))
geocodingDataTask = geocoder.geocode(options) { [unowned self] (placemarks, attribution, error) in
if let error = error {
NSLog("%#", error)
} else if let placemarks = placemarks, !placemarks.isEmpty {
self.resultsLabel.text = placemarks[0].qualifiedName
let foptions = ForwardGeocodeOptions(query: self.inputText.text!)
// To refine the search, you can set various properties on the options object.
foptions.allowedISOCountryCodes = ["US"]
foptions.focalLocation = CLLocation(latitude: Variables.userLat, longitude: Variables.userLng)
let neLat = Variables.userLat + 1.0
let neLng = Variables.userLng + 1.0
foptions.allowedRegion?.northEast = CLLocationCoordinate2D(latitude: neLat, longitude: neLng)
let swLat = Variables.userLat - 1.0
let swLng = Variables.userLng - 1.0
foptions.allowedRegion?.southWest = CLLocationCoordinate2D(latitude: swLat, longitude: swLng)
foptions.allowedScopes = [.address, .pointOfInterest]
let _ = geocoder.geocode(foptions) { (placemarks, attribution, error) in
guard let placemark = placemarks?.first else {
return
}
let coordinate = placemark.location.coordinate
print("\(coordinate.latitude), \(coordinate.longitude)")
self.inputLat.text = coordinate.latitude.description
self.inputLng.text = coordinate.longitude.description
var string = ""
for mark in placemarks! {
if string != "" {
string += "\n"
}
string += mark.qualifiedName
}
self.outputText.text = string
}
} else {
self.resultsLabel.text = "No results"
}
}
}
That gives me a mini-app to test out the data that is returned when I change locations in the Xcode Simulator.
screenshot 2017-07-12 13 54 09
As you can see from this shot, I have centered the map in Jenks, OK (a small town just outside of Tulsa, OK - sort of a 'central US' location.)
When searching for a common place in that area ("Walmart" - which is based in nearby Arkansas, so there are plenty of them around), you can see that only 2 'local' Walmart's come back in the search.
Now, let's move to Bentonville, AR - the home of Walmart......
And, we get two top new results, but the others are the same (and much farther away than Tulsa, OK.....)
We found that if we add the town to the first of the search, the results are much better:
(similar results are true for every search we did - various cities around the US and with other 'common places' like Quiznos (similar results as Walmart when in their home town of Denver, CO...)
As you can see from my code, I tried using the allowedRegion?.northEast and southWest (as I understand it, those should set the search area to about 100 miles around the location, though I'm not sure I set that up right), though no difference was found from this setup (i.e., with/without I get the same results).
The only 'better' results were by putting in the town name along with the 'common' one (though, oddly, different results were returned if the town name was before or after the common one - I didn't check exactly, though I think they are 'best' (i.e., locations are all pretty near) from putting the town name after the common one)
What can I do to get better results without having to tell the user to enter the town name (not a very desirable plan! :)
Thank you in advance for tips - the lookup is a key part of the app (not the test stuff shown in the pictures! ) and users expect to pull up several 'nearby' common places (in this case, we would expect to see all 5 results within something like 20 miles - certainly no more than 100 miles away), so it is an important thing for us that this work much more reliably than we are seeing now.
I'm using the Google Place Picker APi and wanted to know if there is a way to remove the back button and the search button and also prevent the map from moving around, that is created with the _placePicker = [[GMSPlacePicker alloc] initWithConfig:config]; ?
if not, is there an alternative i can use that provides same functionality? Basically, I want the the closest points of interest near a users location..
Thanks.
I'm also trying to figure that out. So far, what I've come up with is to combine GMSMapView and GMSPlacesClient into your own custom viewcontroller.
To gather the nearby points of interest, you'll use the GMSPlacesClient:
placesClient = GMSPlacesClient.sharedClient()
likelyPlace = [GMSPlaces]()
placesClient.currentPlaceWithCallback({ (placeLikelihoods, error) in
if let error = error {
print("Error with Current place: \(error.localizedDescription)")
} else {
if let likelihoodList = placeLikelihoods{
for likelihood in likelihoodList.likelihoods {
let place = likelihood.place
self.likelyPlaces.append(place)
}
}
}
})
this will put the nearby places in your likelyPlaces array. Then it's up to you how you'd want to display the contents. Maybe put them in a tableView or as annotations on the map.
Hope this helps.
I'm trying to build an app showing my favorite spots with swift.
I already store my spot information GeoPoints from parse.com. But I still can't manage to show retrieve the data (spot name and GeoPoints) and pass it to MKMapView. Can someone show me an example to do this?
I also find this question Parse objects as AnnonationPoints, but since I just started learning swift, I don't understand about Objective-C.
really appreciate if anyone can help me. Thank you in advance.
After googling, and trial and error, this is my best answer right now. Hope helps for others!
// retrieve data from parse.com
let query:PFQuery = PFQuery(className: "SpotList")
query.orderByAscending("SpotName")
query.findObjectsInBackgroundWithBlock{ (objects:[AnyObject]! , error:NSError!)-> Void in
if !(error != nil){
for object in objects! {
self.SpotNames.append(object["SpotName"] as String)
self.SpotGeoPoints.append(object["SpotLocation"] as PFGeoPoint)
self.SpotLocationLatitudes.append(self.SpotGeoPoints.last?.latitude as CLLocationDegrees!)
self.SpotLocationLongitudes.append(self.SpotGeoPoints.last?.longitude as CLLocationDegrees!)
var annotation = MKPointAnnotation()
annotation.coordinate = CLLocationCoordinate2DMake(self.SpotLocationLatitudes.last!, self.SpotLocationLongitudes.last!)
annotation.title = self.SpotNames.last!
self.mainMap.addAnnotation(annotation)
self.mainMap.showsUserLocation = true
}
}
}