GMSPlace - can I get this from a set of coordinates - ios

I have coordinates from a user tapping the map on the screen. Can I get the GMSPlace from the Google API by using the coordinates. Couldn't find anything in the documents or online that helped.
Thanks

If you tap on a place, you can also get the place id, then use the place id to create a GMSPlace instance like this:
GMSPlacesClient *placeClient = [GMSPlacesClient sharedClient];
[placeClient lookUpPlaceID:placeID callback:^(GMSPlace * _Nullable result, NSError * _Nullable error) {
if(!error) {
[self updatePlace:result];
}else {
NSLog(#"Error : %#",error.localizedDescription);
}
}];

Related

How to covert a custom class into json array or json dictionary in objective c?

Hi I'm using mobile buy sdk for my eCommerce app.After login I try to save Customer in model manager by using the following code
[self.client loginCustomerWithCredentials:credentials callback:^(BUYCustomer * customer, BUYCustomerToken * token, NSError * _Nullable error) {
if (customer && !error) {
[self.client.modelManager insertCustomersWithJSONArray:customer];
[self.client.modelManager insertCustomerWithJSONDictionary:customer];
}else{
[self showEror:#"LogIn Failed" message:#"Please provide valid Details"];
}
}];
My problem is BuyCustomer is a class i have to convert it into either JsonArray or JsonDictionary so then only I can able to save it. How can I convert BuyCustomer class into either one of above and save it? Thanks in advance.
if you have customer logged in you can use following code to get customer
[self.client getCustomerCallback:^(BUYCustomer * _Nullable _customer, NSError * _Nullable error) {
if (error) {
NSLog(#"Customer error");
}else{
NSLog(#"Customer available");
self.customer = _customer;
}
}];

Get GMSAddress from GMSPlace placeID

Is there any way to get GSMAddress from placeID. I am interested in getting the address by using the placeID obtained from autocompleteQuery method.
P.S: I have a placeID and finding a way to get corresponding GMSAddress in iOS.
I found a thread here but that does not help.
Thanks,
After autocomplete, we do a place look up, then pass the coordinates to GMSGeocoder to retrieve the details, but I am still missing street_name and street_number.
CLLocationCoordinate2D addressCoordinates = CLLocationCoordinate2DMake(latitude,longitude);
GMSGeocoder* coder = [[GMSGeocoder alloc] init];
[coder reverseGeocodeCoordinate:addressCoordinates completionHandler:^(GMSReverseGeocodeResponse *results, NSError *error) {
if (error) {
NSLog(#"Error %#", error.description);
} else {
GMSAddress* address = [results firstResult];
NSLog(#"thoroughfare %#",address.thoroughfare);
NSLog(#"locality %#",address.locality);
NSLog(#"subLocality %#",address.subLocality);
NSLog(#"administrativeArea %#",address.administrativeArea);
NSLog(#"postalCode %#",address.postalCode);
NSLog(#"country %#",address.country);
NSLog(#"lines %#",address.lines);
}
}];
I'm thinking of switching to iOS's own reverse geocoder.
[CLGeocoder reverseGeocodeLocation:[[CLLocation alloc] initWithLatitude:latitude longitude:longitude] completionHandler:
^(NSArray* placemarks, NSError* error) {
It seems there is no direct way to get the GSMAddress from GMSPlace placeID.
One way that I figured out is to use GMSGeocoder().reverseGeocodeCoordinate method along with coordinate property from GMSPlace.
The steps I followed can be summed as:
Use lookUpPlaceID method to find the coordinates
Reverse geocode using the coordinates obtained from lookUpPlaceID
Code is as follows:
placesClient?.lookUpPlaceID(placeID, callback: {
(place, error) -> Void in
// Get place.coordinate
GMSGeocoder().reverseGeocodeCoordinate(place!.coordinate, completionHandler: {
(response, error) -> Void in
for addObj in response.results() {
// Address object
}
})
})
Comments and better solutions are welcome.

iOS: Retrieve Game Center friends who are online

I can retrieve all Game Center friends with this code...
GKLocalPlayer *lp = [GKLocalPlayer localPlayer];
if (lp.authenticated)
{
[lp loadFriendsWithCompletionHandler:^(NSArray *friends, NSError *error)
{
NSLog(#"MY FRIENDS: %#",friends);
if (friends != nil)
{
[GKPlayer loadPlayersForIdentifiers:friends withCompletionHandler:^(NSArray *players, NSError *error)
{
if (error != nil)
{
// Handle the error.
NSLog(#"PLAYERLIST ERROR: %#",[error localizedDescription]);
}
if (players != nil)
{
// Process the array of GKPlayer objects.
NSLog(#"PLAYERS: %#",players);
}
}];
}
}];
}
... however, is there a way to retrieve only the friends with GameKit who are online?
It does not look like you are able to. Since GKPlayer does not offer any way to view if a player is online or not.
Also since technically once a person logs on to Game Center they are "Online" till they log off. Meaning they could be online for days while using their phone. When they are logged on if you send them an invite they will get the trumpet noise.
http://developer.apple.com/library/IOS/#documentation/GameKit/Reference/GKPlayer_Ref/Reference/Reference.html#//apple_ref/doc/uid/TP40009599

Facebook IOS SDK: store facebook request callback data into global variable

I'm using the new facebook ios sdk. I request for friends data using the new function showed below. However, since it is a function with a block as a parameter I lost these data outside the function. How can I preserve the data (i.e. store in a global variable) so that I can use it in another function?
Thanks in advance.
code:
-(void)requestFriends {
[FBRequestConnection startForMyFriendsWithCompletionHandler:^(FBRequestConnection* connection, id data, NSError *error) {
if(error) {
[self printError:#"Error requesting /me/friends" error:error];
return;
}
NSArray* friends = (NSArray*)[data data];
}];
Just store it on a property, and refresh the UI after that.
// in .h or class extension
#property(nonatomic, strong) NSArray *friends;
-(void)requestFriends {
[FBRequestConnection startForMyFriendsWithCompletionHandler:^(FBRequestConnection* connection, id data, NSError *error) {
if(error) {
[self printError:#"Error requesting /me/friends" error:error];
return;
}
self.friends = (NSArray*)[data data];
}];

gamecenter turnbased save match data out of turn

Any chance I can save/update matchdata even when it is not my turn?
[currentMatch saveCurrentTurnWithMatchData:data completionHandler:^(NSError *error) {
if (error)
{ }];
The above code can be used if it is still this user's turn, but what if it is not this user's turn? How do I send data between two players?
As of iOS 6.0, you cannot. :(
You can save match data without advancing the turn (assuming you are
the current player). see - saveCurrentTurnWithMatchData:completionHandler:
You can end a game out of turn. see - participantQuitOutOfTurnWithOutcome:withCompletionHandler:
However, you cannot update match data out of turn.
GKTurnBasedMatch Reference
Try this
- (void) advanceTurn
{
NSData *updatedMatchData = [this.gameData encodeMatchData];
NSArray *sortedPlayerOrder = [this.gameData encodePlayerOrder];
this.MyMatch.message = [this.gameData matchAppropriateMessage];
[this.myMatch endTurnWithNextParticipants: sortedPlayerOrder turnTimeOut: GKTurnTimeoutDefault
matchData: updatedMatchData completionHandler ^(NSError *error) {
if (error)
{
// Handle the error.
}
}];
}

Resources