I am trying to make a simple app which allows the user to get the longitude and latitude corresponding to a specific address. I want to provide the user with a search box similar to the one in google maps. Specifically I would like some sort of autocompletion to ensure the user enters a valid address. Is it possible to create an instance of google maps search box?
SPGooglePlacesAutocomplete is a simple objective-c wrapper around the Google Places Autocomplete API.
Look at this API from github which might be helpful- https://github.com/spoletto/SPGooglePlacesAutocomplete
Usage shown as per link. Adding the .h file you can have access to the functions which implement the Google places API from within the function. You can set parameters like partial address string, radius, language your app uses, your location (lat,long)
#import "SPGooglePlacesAutocompleteQuery.h"
...
SPGooglePlacesAutocompleteQuery *query = [SPGooglePlacesAutocompleteQuery query];
query.input = #"185 berry str";
query.radius = 100.0;
query.language = #"en";
query.types = SPPlaceTypeGeocode; // Only return geocoding (address) results.
query.location = CLLocationCoordinate2DMake(37.76999, -122.44696)
Then, call -fetchPlaces to ping Google's API and fetch results. The resulting array will return objects of the SPGooglePlacesAutocompletePlace class.
[query fetchPlaces:^(NSArray *places, NSError *error) {
NSLog(#"Places returned %#", places);
}];
It also has a example project which can be used.
Related
We are creating a pin in a specific Board by using the method
createPinWithImageđź”—onBaord:description:progress:withSuccess:andFailure:
We read in the documentation (here: https://developers.pinterest.com/docs/api/overview/ and here: https://github.com/pinterest/ios-pdk/blob/master/Pod/Classes/PDKClient.h#L417) that this method should return a PDKResponseObject *responseObject with the ID, URL, clickthrough URL and description of the created Pin.
We have been creative enough to try to access the ID of the Pin and its URL using any possible key (#"id", #"identifier", #"url", #"NSUrl") but the values returned are always nil. In fact the PDKResponseObject returns only 2 keys: Board ID and Pin Description.
What should we do to access the ID or, at the very least, the URL of the newly created Pin?
Does anybody have the same issue?
Despite multiple attempts and after having tried to discuss this issue with the Pinterest development Team, this still remains.
Testing a solution becomes also extremely difficult considering the new limitation Pinterest has imposed on not approved apps (which include all apps under development by definition).
For now, I only found a way around by calling a new request to get all pins in a specific board and get the first in the resulting array (which is the last posted):
//Create pin in Pinterest
[[PDKClient sharedInstance]createPinWithImage:image link:urlToShare
onBoard:reference description:message progress:nil
withSuccess:^(PDKResponseObject *responseObjectCreation) {
//Previous block does not return pin id so a new call is required
[[PDKClient sharedInstance]getBoardPins:reference fields:[NSSet
setWithArray:#[#"link"]] withSuccess:^(PDKResponseObject
*responseObject) {
//Get id of last pin
NSArray *pinIDs = [[NSArray arrayWithArray:[responseObject
pins]]valueForKey:#"identifier"];
NSString *postId = [pinIDs objectAtIndex:0];
}];
}];
By the way, the right key for the pin ID is "identifier" and not "id" or "ID" as said in the API documentation. Just found out by trying multiple times and checking the Pinterest Example app in GitHub.
Hope this helps other people who are fighting the same problem.
There are problems with auto complete, to me google autocomplete search bar is filling writes all cities in the world but I need only the address of my city.
You can use the GMSCoordinateBounds, which is
A object which restrict the results to a specific area specified by latitude and longitude bounds.
In additional, There are some Location Biasing options for the JS API, but no sure if iOS API has them too.
I found information, we cant search just in city.We can minimum set search in Country. Google say - they will fix it in next version.
NSMutableString *url = [NSMutableString stringWithFormat:#"https://maps.googleapis.com/maps/api/place/autocomplete/json?input=%#&sensor=%#&components=country:%#""&key=%#",
[input stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
SPBooleanStringForBool(sensor), countryCode,key];
This worked for me:
GMSVisibleRegion visibleRegion = self.mapView.projection.visibleRegion;
GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:visibleRegion.farLeft coordinate:visibleRegion.nearRight];
My code is virtually identical to the following example:
https://github.com/iamamused/Example-MKLocalSearch.git
Here are the important bits:
#interface ViewController : UIViewController
#property (strong, nonatomic) IBOutlet MKMapView *ibMapView;
#end
#implementation ViewController {
MKLocalSearch *localSearch;
MKLocalSearchResponse *results;
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
[localSearch cancel];
MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init];
request.naturalLanguageQuery = searchBar.text;
request.region = self.ibMapView.region;
localSearch = [[MKLocalSearch alloc] initWithRequest:request];
[localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error){
[self.resultTable reloadData];
}
}
It seems reasonable that when Sutter and Mason aka 600 Sutter St. are inside the map region searching for "600 Sutte" would include the obvious result "600 Sutter St.". I just can't get that to work. I've tried many different streets and I often get results out of state before I get results that are directly in the map region.
Also, "600 Sut" returns irrelevant results, while "600 Su" returns an error 4. Did it really not find anything that starts with "600 Su"?
Am I using this API completely wrong or is it not meant for what I'm trying to do with it?
Map Region for all queries:
600 Sutte
600 Su
I ended up giving up on Apple local search API and switching to Google. Their Place API is exactly what I needed. It finds relevant results quickly and up to 100k requests per day doesn't cost anything.
Auto-complete:
https://developers.google.com/places/documentation/autocomplete
Details (need this for lat, lon):
https://developers.google.com/places/documentation/details
With the help of JSONModel I built it into my iOS app in a few hours.
The results are exactly what I was hoping to see:
#borisz - too few points to comment directly..BEWARE of using Google Places API in your IOS app. Google states in their terms and conditions that any map displaying data fetched from Google Places API needs to be a Google Map. So if you still wish to use their API and search, just make sure that you are also using a Google Map and not Apple's native maps. Hope this helps - goodluck!
Posting this for those who still have similar problem.
You shouldn't use MKLocalSearchRequest() instead use MKLocalSearchCompleter which gives better results and is used in current Apple Maps.
You can learn how to implement in this
answer
I am trying to integrate GooglePlus inside an iOS app of mine.
The app sends a simple message. I have a few questions about the setting of the recipient(s).
Here is the kind of code I am using:
[GPPShare sharedInstance].delegate = self;
id<GPPNativeShareBuilder> shareBuilder = [[GPPShare sharedInstance] nativeShareDialog];
[shareBuilder setPrefillText:#"Hello world! How is everything?"];
[shareBuilder setPreselectedPeopleIDs:#"112233445566778899000"]; // Question point!!
if (![shareBuilder open]) {
NSLog(#"Status: Error (shareBuilder cannot open).");
}
When the line with the comment "Question point!!" is present, I can set one(or a few) individual(s) as recipient(s) of the message.
When it is not present the set of recipients defaults to "Friends".
Here are my two questions:
Is it possible to set one of my circles (or a community) as recipient? Not only "Friends".
When using the "setPreselectedPeopleIDs:" method, one needs the ID of the recipient. How do we find this ID? There are documents and videos on the net showing how to find one's own ID, but since people usually send messages to other peole rather than to themselves, it would also be useful to know how to get other's IDs.
Doesn't seem like you can share with a specific circle.
You can use this method to get all of the visible people in the user's circles using this method
queryForPeopleListWithUserId:collection:
which is outlined here:
https://developers.google.com/+/mobile/ios/people
Explanation of the parameters from the header:
// List all of the people in the specified collection.
// Required:
// userId: Get the collection of people for the person identified. Use "me" to
// indicate the authenticated user.
// collection: The collection of people to list.
// kGTLPlusCollectionVisible: The list of people who this user has added to
// one or more circles, limited to the circles visible to the requesting
// application.
And another question that goes into this a little bit:
How to Fetch Google Plus circles in IOS Sdk
It does not seem to me like you can discern who is in what circle, unfortunately.
I'm using the iOS 6.0 SDK and I would like to route between two different addresses (not latitude and longitude) with Apple's new iOS 6.0 maps. I would like to show the indications too.
How can I do this?
I looked into do doing this last week and did not figure out a way to do it. It appears that you can give a destination, and you can sort of give it more than just coordinates, but it always assumes your starting position is the current location. That is limiting when you may be planning a trip while you are not currently at the starting location. (But perhaps I am just not seeing how it is done and I hope someone can correct me if that is true.)
A while back I looked into routing options for iOS 6 and gathered the results here...
How would you providing routing for directions between points on a map? What are the missing pieces?
You still may not be able to open up Apple Maps with the exact routing that you want, but perhaps you can draw the route with overlays and annotations on your own instance MKMapView. That may be the best you can do for now.
Below is the code that I used to route to a location and provide at least a label for the destination instead of leaving it to only coordinates. I found that simply giving the destination a label with the full address details would not work, so I just provide that one value.
if (flag != DirectionsFlag_PublicTransit && itemClass && [itemClass respondsToSelector:#selector(openMapsWithItems:launchOptions:)]) {
NSDictionary *address = #{ (NSString *)kABPersonAddressStreetKey : location.title };
MKPlacemark *destinationPlacemark = [[MKPlacemark alloc] initWithCoordinate:location.coordinate addressDictionary:address];
MKMapItem *destinationMapItem = [[MKMapItem alloc] initWithPlacemark:destinationPlacemark];
if (flag == DirectionsFlag_Driving) {
[destinationMapItem openInMapsWithLaunchOptions:#{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}];
}
else if (flag == DirectionsFlag_Walking) {
[destinationMapItem openInMapsWithLaunchOptions:#{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeWalking}];
}
}
This code specifically does not handle Public Transit directions since Apple Maps does not do that. I instead have it open up Google Maps with the URL that I was using previously which now opens up Safari for those directions. The flag is an enum value of Driving, Walking or Public Transit. The location is a model which contains various details including title and coordinates.