IPhone Google Location API V3 get all near location from current position - ios

how to get all near location from passing current location lat & log to google location api ?
i have registered google location api and created url to fetch all near location , but the problem is at a time i am only able to pass one "types" e.g types = atm
i want to pass multiple types like "atm|bar|cafe|florist|park" so that i can able to get all the information by passing single request.
below is url which i am passing
URL : https://maps.googleapis.com/maps/api/place/search/json?location=23.025651,72.507753&radius=4754796&types=bar|cafe&sensor=false&key=AIzaSyDtsmfnmSKSgDGK4s5
But by passing spurted by "|" it will give no records , by passing single type only it will provide full details.
Please help me.
Thanks

I found the solution to request the multiple types for Place API V3 , below is the code by which we can request multiple types and get all near location information.
currentCentre.latitude = 23.025651;
currentCentre.longitude = 72.507753;
NSString *url = [NSString stringWithFormat:#"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=%#&types=atm|food&sensor=true&key=%#", currentCentre.latitude, currentCentre.longitude, [NSString stringWithFormat:#"%i", 1000], kGOOGLE_API_KEY];
NSURL *googleRequestURL = [NSURL URLWithString:[url
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
// Retrieve the results of the URL.
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL: googleRequestURL];
[self performSelectorOnMainThread:#selector(fetchedData:) withObject:data waitUntilDone:YES];
});
From the FetchedData we will get the JSON Response from google and we can able to get all details of requested different types in single request.
Thanks.

Related

Twiiter API failed to get followers and following details

I want to get the twitter followers and following person details. i know that not present any direct mechanism to get all the detail. so i first get the id's of all friends. i used this API to get the id's.
NSURL * requestAPI =[NSURL URLWithString:#"https://api.twitter.com/1.1/friends/ids.json"];
NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:twitterAccount.username, #"screen_name", nil]; // Fo rthis Api you need to pass these parmeter is necessary
and pass this parameter and get the list of id's.
and using that ids i want to get the all details about friends. so i tried this API
NSURL * requestAPIForNames =[NSURL URLWithString:[NSString stringWithFormat:#"https://api.twitter.com/1.1/users/lookup.json?user_id=%#",result]];
NSMutableDictionary *parameters1 = [[NSMutableDictionary alloc] init];
[parameters1 setObject:#"xxxxxxxxxxxxxxxxxxxx" forKey:#"oauth_consumer_key"];
[parameters1 setObject:#"xxxxxxxxxxxxxxxxxxxxxxxx" forKey:#"oauth_consumer_secret"];
i have pass the all id's to this API. and want to get the details of followers. but not sucess.
i get the following issue.
{
errors = (
{
code = 32;
message = "Could not authenticate you";
}
);
}
why this happening can anyone help me to do this.
thanks in advance.

How to differentiate different types of Web Services according to URL?

So I have finally created a VERY simple application in which I invoke a web service and NSLog the JSON data. I have used about 3 web services so far, and all of them look different. For example, in the small little app I made I used two different URLS. My code is below:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *urlString = [NSString stringWithFormat:#"http://ielmo.xtreemhost.com/array.php"];
NSString *urlString2 = [NSString stringWithFormat:#"http://bookapi.bignerdranch.com/courses.json"];
NSURL *url = [NSURL URLWithString:urlString2];
NSData *data = [NSData dataWithContentsOfURL:url];
NSError *error;
NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(#"%#", json);
// Do any additional setup after loading the view, typically from a nib.
}
My question is how come I can NSLog BOTH of those link's json data fine even if one of them is a .php url. Sorry for such a nooby question but I want to go about looking for web services I can use, and I want to be able to know how to look, because when I look for my own web services, they don't end up working.
There's no way you can differentiate the content of a URL by the URL itself (unless it's an HTML)
The contents of a URL depend on what the server wants to serve. You can have an http://www..../something.php for example, and there's no way to know what you'll get, it could be an HTML page, it could be a PDF document, it could be a zip file, or it could be JSON content.

NSMutableURLRequest and JSON - How would I finish this connection?

I am trying to fetch data from an api and I have this code:
// create the URL we'd like to query
NSString *urlString = [NSString stringWithFormat:#"https://www.googleapis.com/adsense/v1.1/reports"];
NSString *token = auth.accessToken;
NSMutableURLRequest *myURL = [NSURL URLWithString:urlString];
[myURL addValue:token forHTTPHeaderField:#"Authentication"];
// we'll receive raw data so we'll create an NSData Object with it
######
How would I complete this step? So far I have
NSData *myData =
######
// now we'll parse our data using NSJSONSerialization
id myJSON = [NSJSONSerialization JSONObjectWithData:myData options:NSJSONReadingMutableContainers error:nil];
// typecast an array and list its contents
NSArray *jsonArray = (NSArray *)myJSON;
NSLog(#"%#", jsonArray);
How would I connect on the 9th line?
It looks like you are putting all this code in one place (making a synchronous network request). This is typically a bad idea. You should put the first part (creating and starting the request) in one place, and put the parsing code in a separate method / block that gets called once the request is completed. (This is called an asynchronous network request.)
You should take a look at +[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]. You can pass your NSURLRequest in here, and then specify the completion (parsing, etc.) in the completion handler. It will give you the NSData object you're looking for - see documentation here.
If you have more than a handful of network connections, this can get unwieldy. You may want to look at a third party library like AFNetworking, which can manage much of the tedious stuff for you, and let you focus on calling a URL, and parsing the response.
You need:
NSData *myData = [NSURLConnection sendSynchronousRequest:myURL returningResponse:nil error:nil];
This is a synchronous call. I'll suggest always using asynchronous webcalls is a good way.

Facebook feeds on iOS app?

How can I display face book feeds related to a group on an iOS App?
Is there any JSON/JSONP call to fetch the feeds??
Any help is Appreciated.
The simplest - is just to show a web page on web view. Facebook manages itself to fit the width of your webView control.
// Load facebook data
NSString *fbUrlAddress = #"http://www.facebook.com/FLORtiles"; // here you put your own group
//Create a URL object.
NSURL *fbUrl = [NSURL URLWithString:fbUrlAddress];
NSString *webHTMLfb = [NSString stringWithContentsOfURL:fbUrl encoding:NSUTF8StringEncoding error:NULL];
//NSLog(#"webHTML of facebook: %#", webHTMLfb);
//URL Requst Object
NSURLRequest *fbRequestObj = [NSURLRequest requestWithURL:fbUrl];
//Load the request in the UIWebView.
[fbWebView loadRequest:fbRequestObj];
You might need to get familiar with Facebook's Graph Api
Go through this -> https://developers.facebook.com/docs/mobile/ios/build/

NSMutableArray writeToUrl

Is it possible to use the:
[NSMutableArray writeToURL:(NSString *)path atomically:(BOOL)AuxSomething];
In order to send a file (NSMutableArray) XML file to a url, and update the url to contain that file?
for example:
I have an array and I want to upload it to a specific URL and the next time the app launches I want to download that array.
NSMutableArray *arrayToWrite = [[NSMutableArray alloc] initWithObjects:#"One",#"Two",nil];
[arrayToWrite writeToURL:
[NSURL urlWithString:#"mywebsite.atwebpages.com/myArray.plist"] atomically:YES];
And at runtime:
NSMutableArray *arrayToRead =
[[NSMutableArray alloc] initWithContentsOfURL:[NSURL urlWithString:#"mywebsite.atwebpages.com/myArray.plist"]];
Meaning, I want to write an NSMutableArray to a URL, which is on a web hosting service (e.g. batcave.net, the URL receives the information and updates server sided files accordingly.
A highscore like setup, user sends his scores, the server updates it's files, other users download the highscores at runtime.
As for part one of your question,
I'll assume you want to use the contents of a NSMutableArray to form some sort of a URL request (like POST) that you will send to your web service and expect back some information...
There is no prebuilt way of sending the contents of a NSMutableArray to an URL but there are simple ways of doing this yourself. For example, you can loop through the data of your array and make use of NSURLRequest to create a URL request that complies with the interface of your web service. Once you've constructed your request you can send it by passing it a NSURLConnection object.
Consider this very simple and incomplete example of what the client-side code might look like using an Obj-C array to provide data...
NSMutableData *dataReceived; // Assume exists and is initialized
NSURLConnection *myConnection;
- (void)startRequest{
NSLog(#"Start");
NSString *baseURLAddress = #"http://en.wikipedia.org/wiki/";
// This is the array we'll use to help make the URL request
NSArray *names = [NSArray arrayWithObjects: #"Jonny_Appleseed",nil];
NSString *completeURLAsString = [baseURLAddress stringByAppendingString: [names objectAtIndex:0]];
//NSURLRequest needs a NSURL Object
NSURL *completeURL = [NSURL URLWithString: completeURLAsString];
NSURLRequest *myURLRequest = [NSURLRequest requestWithURL: completeURL];
// self is the delegate, this means that this object will hanlde
// call-backs as the data transmission from the web server progresses
myConnection = [[NSURLConnection alloc] initWithRequest:myURLRequest delegate: self startImmediately:YES];
}
// This is called automatically when there is new data from the web server,
// we collect the server response and save it
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSLog(#"Got some");
[dataReceived appendData: data];
}
// This is called automatically when transmission of data is complete
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
// You now have whatever the server sent...
}
To tackle part 2 of your question, the receiver of a web request will likely require some scripting or infrastructure to make a useful response.
Here, Answer in this question:
Creating a highscore like system, iPhone side
I couldn't edit my post because I posted from my iPhone as an anonymous user, sorry.

Resources