在MKMapView上搜索和显示商家位置 [英] Search and display business locations on MKMapView

查看:96
本文介绍了在MKMapView上搜索和显示商家位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试寻找一种搜索商家的方法,例如杂货店,并将其显示在用户当前位置周围的Google地图上。这曾经非常简单,使用旧的URL样式启动苹果地图位置,但我无法找到如何使用MKMapView。我知道我需要使用MKAnnotations类,但我的问题是找到数据。我已经尝试插入以下网址以获取谷歌的信息,但数据的大小似乎太大了。

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 =杂货& mrt = yp& sll = 37.769561,-122.412844& z = 14& output = kml

有没有简单的方法可以设置一个属性,告诉MKMapView搜索关键字并显示我当前位置周围的所有匹配业务?或者有人知道如何从谷歌获取此信息?

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?

推荐答案

该搜索返回的KML文件中包含大量信息。 MKMapView 无法查询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:


  1. 使用从 NSXMLParser 获得的查询数据,只提取您感兴趣的内容(可能是标题,纬度,经度) 。 KML只是XML的一个版本。

  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.

查看Google文档以查找提供更轻量级数据格式的调用。您可以将网址中的格式更改为json,但其中的信息是相同的。

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.

该文件仅限虽然约50KB。根据我的经验,下载和解析一个50KB的XML文件比3G要花费大约5秒。

The file's only about 50KB though. In my experience, downloading and parsing a 50KB XML file takes about 5 seconds over 3G.

编辑:刚发现这个,以为你可能是感兴趣:

Just found this, thought you might be interested:


许多人通过JSON将数据传输到Web服务或从Web服务传输到iPhone。这是一种比使用XML更好的方法。在iPhone上解析XML简直太糟糕了。它过于复杂,令人困惑。目前,YouVersion应用程序圣经使用JSON从服务器来回传输所有内容,这一切都很有效。

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.

如果你真的没有选择,那么至少使用JSON。这是一个很棒的JSON库,我目前使用
http:// code。 google.com/p/json-framework/

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/

从这里: http://samsoff.es/post/iphone-plist-tutorial/

您可以通过将请求字符串更改为此来获取JSON:

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

另一个编辑

这是另一个名为Touch JSON的JSON库。我已经使用过这个了,它很容易实现。

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

这篇关于在MKMapView上搜索和显示商家位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆