I am writing an iphone application when you give a search text, it locate possible addresses.
I was thinking there maybe some Google API for this. I have seen several applications with this feature.
Can anyone provide some information on this?
If you've found the API you want (looks like you have), the basic idea is to use NSURLRequest, NSURLConnection, and NSMutableData to construct a url (ie. http://maps.googleapis.com/maps/api/geocode/output?parameters) and load the resulting data into your application.
From there, I would make use of a JSON parsing lib to convert the result string into an NSDictionary, so that you can use it easily in your app. This one is my favorite: http://code.google.com/p/json-framework/
good luck!
Related
I need to display a list of latest tweets in my iPhone app, and wondering what is the best way to do this, is there any SDK or existing projects doing this? I know about ShareKit, but it seems to be a method for sharing with standard UI, and no way to use it as a getter for latest tweets.
Thanks!
If you only need to get publicly available data, then Twitter has a pretty straight-forward HTTP API that outputs JSON.
For example, to get a user's tweets: http://dev.twitter.com/doc/get/statuses/public_timeline
You can easily use it by utilizing available library for JSON parsing (e.g. JSONKit) and HTTP client (e.g. ASIHTTPRequest, or NSData's + dataWithContentsOfURL).
U see the following example.you will get some idea
http://mobile.tutsplus.com/tutorials/iphone/twitter-api-iphone/
There is also a third way, which is using http://three20.info/, that also implements main Twitter methods, but since all that you want is to retrieve public info I would stick with ASIHTTPRequest, as Barum Rho recommended. Easier and quicker.
Just to let you know more ways :)
In my application i need to create and save data into an xml file on my webspace and then i want to parse that xml into my iphone app. The question here is this is being done by two different parties a sender and a receiver.
But i don;t know how to parse that xml file into my app when i don't have the excat url of that xml because there will be number of people who will be using this app so how i can allocate the xml a specific url and pass that url at receiver end.
Thanks,
As there is a lot to this question I can only give you a vague answer to keep it short. The type of communication I recommend using is NSURLConnection. That will allow you to get the contents of say an xml from a URL.
As far as identifying individual users there is a few ways all of them a fair bit of work. You could create a sign in where the user has a unique username or email. Store that in the database on your server and pass it as part of the url.
You could also sort of use push notification registration where your server is required to keep an iPhone unique identifier to push information to Apple. I don't know enough to push notification to give you much guidance in this but if you don't want the user to create an account I think this would be the way. You could also query the server for a unique ID and store it in NSUserDefaults.
I would recommend the user account creation though. Also have a look at NSXMLParser for your xml parsing.
Beyond this help ask a more specific question. There are also many other ways to do this, its just the way I do it.
I can help you with the parsing of the XML.
iOS (like mac) has a built in XML parser.
Still I would recommend you use an external library, there are several available out there.
In a recent project, I very successfully used TouchXML: http://github.com/schwa/TouchXML
Here is a very simple tutorial on how to use the TouchXML library to parse XML files:
http://foobarpig.com/iphone/parsing-xml-element-attributes-with-touchxml.html
I am new to iPhone programming and would like to be able to use the BLAST (is a bioinformatics server) URL's API from the iPhone. I would like to write a very simple application that queries the BLAST server and make some query. I have found the following
I have found the following documentation on BLAST (http://www.ncbi.nlm.nih.gov/BLAST/Doc/urlapi.pdf).
I am not sure from where I should start.. I checked out the following on security concepts for Mac OS X and iOS(http://developer.apple.com/iphone/library/documentation/Security/Conceptual/Security_Overview/Concepts/Concepts.html) and then found CFNetwork library (http://developer.apple.com/iphone/library/documentation/Networking/Conceptual/CFNetwork/Introduction/Introduction.html).
But I don't really know from where to start..
theoretically I would like to query the BLAST url API from a .mm class method (so I can use standard C) and then show the results in a normal view.
Anyone would be able to guide me in these first steps?
Best regards and Many thanks!
The BLAST API is strange. It is a POST-only command-response API, but the commands you POST are things like CMD=Get&..., CMD=Put&..., etc.
The iPhone SDK provides a fairly convenient high level way to invoke URLs. Have a good read of the NSURLRequest documentation. You'll need to set the HTTPMethod property to POST, and populate the HTTPBody with whatever the BLAST API tells you to post.
I'm trying to find a way to search for a business, such as "grocery stores" and display them on a google map around the users current location. This used to be pretty simple with the old URL style of launching the apple map location but I can't find out how to do it with the MKMapView. I understand that I'll need to use the MKAnnotations classes but my problem is with finding the data. I've tried plugging in the URL below to get the info from google but the size of the data seems way too large.
http://maps.google.com/maps?q=grocery&mrt=yp&sll=37.769561,-122.412844&z=14&output=kml
Is there an easy way to just set a property that tells the MKMapView to search for a keyword and display all matching business around my current location? Or does anybody know how to get this information from google?
The KML file that's returned by that search has a lot of information in it. MKMapView doesn't have a way to query Google, so you have a couple of choices:
Use the data that you get from that query with NSXMLParser, and only extract the things you're interested in (probably title, latitude, longitude). KML is just a version of XML.
Look through the Google docs to find a call that gives a more lightweight data format. You can change the format in your url to json, but the information in it is the same.
The file's only about 50KB though. In my experience, downloading and parsing a 50KB XML file takes about 5 seconds over 3G.
Edit: Just found this, thought you might be interested:
Many people transfer data to and from web services to the iPhone via JSON. This is a much better way than using XML. Parsing XML on the iPhone just plain sucks. It's overly complicated and super confusing. Currently the YouVersion app, Bible, uses JSON to transfer everything back and forth from the server and it all works great.
If you don't really have a choice, at least use JSON. Here is a great library for JSON that I currently use
http://code.google.com/p/json-framework/
From here: http://samsoff.es/post/iphone-plist-tutorial/
You can get JSON by changing the request string to this:
http://maps.google.com/maps?q=grocery&mrt=yp&sll=37.769561,-122.412844&z=14&output=json
Another Edit
Here's another JSON library called Touch JSON. I've used this one, and it's quite easy to implement.
https://github.com/acf/TouchJSON
Rather than using the maps?q= string, it is better to use the the official API here:
http://code.google.com/apis/maps/documentation/geocoding/
The JSON replies of the API work with the JSON Parser http://code.google.com/p/json-framework/ better (the other URL doesn't return compliant JSON, and isn't a standard API so may be more subject to change).
Okay this is a fairly broad question. This is my first App and I'm not sure the best way to go about this. The app is on the IPHONE.
I have a 'Restaurant' class. The restaurant has many different attributes and opening times.
I currently store a restaurant in an instance of nsdata (it complies to NSCoding) LOcal storage is easy and I just use nsdata.
I have just built in an import/export function. I want these two methods to "post" a restaurant to the web and "get" a restaurant from the web. I know I can do this with NSUrlConnection and I have it up and working.
However I want to be cleverer about it. For instance what if I want to take my online list of restaurants that have been submitted and build a web interface that can also interact with the data?
This is what I am thinking so far:
Create a 'toString' method that will convert my class into a textual representation. Then store the string on a server. This will replace storing nsdata online. Does this sound appropriate?
However, I want to be able to query the amount of restaurants and have a bit more control over my online 'database'. Is XML the answer? I was about the start looking into Amazon Web Services and learn either Json or Rest.
Any bits of advice?
Thanks
Dan
I am not very familiar with iPhone development yet, but if there are reasonably easy way to consume web services I would recommend using that with typed parameters. This would make these services more "usable" from other systems too, they would not need to know how to serialize/pack objects to a string but only how to call a function: storeRestaurang(string name, int rating...) etc.
This is an article I will check out myself since I hope to get into iPhone development a bit more: http://icodeblog.com/2008/11/03/iphone-programming-tutorial-intro-to-soap-web-services/
Looks like you want to use a plist.
Any of the cocoa collection classes can be written out to a plist, which is a breed of xml file. The sweet part is if you use standard cocoa value classes, you can write the collection out, and read it back in later.
NSString, NSNumber, NSDate, NSData, NSAray, NSDictionary objects can be put into a collection and stored to a plist directly. Other classes will have to be serialized into NSData then written to disk as a plist. For truly custom data, an NSKeyedArchiver is probably what you want.
For simple strings and numbers data, pack it all into an NSDictionary and then write it to a plist. Now look around on your mac and you'll see just how popular plists are.
NSDictionary API - Storing Dictionaries
Property List Programming Guide
Archives and Serializations Programming Guide for Cocoa
Learn about REST, it's the easiest and cleanest way to provide a web-based API. Some frameworks, like Ruby on Rails, give you a REST interface right out of the box.
Then, you'll need to find a way to convert your objects on the iPhone into a REST-friendly format. XML and JSON are both options, but unfortunately I haven't seen any code for converting to/from XML or JSON that I can really recommend, since I haven't tried any just yet. But, there are some projects that might lead you in the right direction. One of the most promising-looking is this:
http://github.com/yfactorial/objectiveresource/tree/master