Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
461 views
in Technique[技术] by (71.8m points)

iphone - Search and display business locations on MKMapView

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:

  1. 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.

  2. 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...