Search and display business locations on MKMapView

前端 未结 2 1183
生来不讨喜
生来不讨喜 2020-12-16 06:55

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 si

相关标签:
2条回答
  • 2020-12-16 07:34

    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

    0 讨论(0)
  • 2020-12-16 07:34

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

    0 讨论(0)
提交回复
热议问题