使用CLLocation和/或Mapkit从坐标中查找公司名称信息 [英] Looking for business name information from coordinates using CLLocation and/or Mapkit

查看:109
本文介绍了使用CLLocation和/或Mapkit从坐标中查找公司名称信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试使用通过CLLocationManager返回的坐标来查看它们是否与任何本地企业紧密匹配-例如,如果我碰巧站在星巴克,我希望我的应用根据我的坐标提出建议我当时站在星巴克.如果我在星巴克(Starbucks)外面20米,但那是离我站立的地方最近的地址,我希望它提示"Starbucks".

I'm trying to use coordinates returned using CLLocationManager to see if they are a close match for any local business - if I happened to be standing in a Starbucks for example, I would want my app to suggest that based on my coordinates I was standing in Starbucks. If I was 20 metres outside Starbucks, but it was the closest address to where I was standing, I would want it to suggest 'Starbucks'.

我可以毫无问题地返回CLPlacemarks,但是它们所包含的信息在任何地方都不会包含公司名称.我在英国,例如,位于伦敦格洛斯特路的Nando的地址为伦敦格洛斯特路170号,SW7 4ST".我可以在CLPlacemark信息中返回伦敦格洛斯特路170号,SW7 4ST,但没有问题,但没有地方提到Nando.

I can return CLPlacemarks no problem, but the information they contain does not contain the business name anywhere. I am in the UK, so, for example, Nando's on the Gloucester Road in London has an address of '170 Gloucester Road, London, SW7 4ST'. I can return 170 Gloucester Road, London, SW7 4ST in the CLPlacemark info no problem, but nowhere does it mention Nando's.

我在各种帖子中读到,该信息可能在name属性,感兴趣的区域甚至在格式化的address属性之内,但我在伦敦市中心进行的广泛测试表明,无论如何,在英国并非如此.即使在美国,"Apple Inc"也只会在其1无限循环之前在其地址的格式化地址属性中提及.

I read in various posts that the info might in the name property, or area of interest or even within the formatted address property, but my extensive testing in Central London suggests that isn't the case, in the UK at any rate. Even in the US, "Apple Inc" is only mentioned within its address's formatted address property before 1 Infinite Loop.

我尝试通过使用CLLocation获取用户的坐标,然后将其用作程序化MapKit搜索的基础来实现此目的-这样只会再次返回地址,而不是公司名称.

I tried to accomplish this instead by getting the user's coordinates using CLLocation and then using them as a basis for a programmatic MapKit search - this just returns the address again, not a business name.

我还对Apple Maps应用程序进行了一些最终用户测试,否则我会非常喜欢.如果在本地进行一般搜索(例如),似乎返回的结果不完全. 酒吧",餐厅".即使我知道附近有更多的餐馆,也包括了一些当地的地方,而没有其他地方,有时结果包含的地方也很远.

Having also done a bit of end-user testing of the Apple Maps app, which I am otherwise a huge fan of, it seems to return fairly incomplete results if searching locally generally for e.g. 'bar', 'restaurant'. Some local places are included, others aren't, sometimes the results contain places which are quite far away, even though I know that there are many more restaurants in the immediate vicinity.

我很快得出结论,要实现我想要的唯一方法就是使用Google Places API,出于某些原因,我希望避免使用Google Places API,尤其是我相当缺乏iOS编程经验(在Swift btw中). ..)

I am fast concluding the only way to achieve what I want is to use the Google Places API, which I was hoping to avoid for a number or reasons, not least my considerable lack of experience at iOS programming (in Swift btw...)

如果任何人都可以明确建议Mapkit无法在本地执行此操作,而我需要使用Google Places API,那么至少我知道并且可以继续使用它-但是,如果有办法,我将不胜感激知道它是什么...

If anyone can definitively advise that there is no way to do this natively in Mapkit and that I need to use Google Places API, then at least I know, and can just get on with it - but if there is a way, I would be most grateful to know what it is...

提前谢谢!

推荐答案

我在MapKit中也遇到了类似的问题,过了一会儿,发现Google place API对于此类任务要好得多,请检查此

I have encounter similar issues with MapKit, and after a while found that Google places API is much better for this kind of task check this link to find sample code on how to use Google Places to get current location

基本上,您需要

-安装Google Places SDK

-将Google映射到您的班级

-Import Google maps to your class

import GoogleMaps

-在课程上添加一个场所客户

-Add a places client on class

var placesClient: GMSPlacesClient?

-在您的viewDidLoad()上初始化您的Places客户端

-Init your places client probably on your viewDidLoad()

placesClient = GMSPlacesClient()

-并在需要它的位置添加此代码以搜索当前位置

-And add this code where you need it to search for the current place

placesClient!.currentPlaceWithCallback({ (placeLikelihoods, error) -> Void in
  if error != nil {
    print("Current Place error: \(error.localizedDescription)")
    return
  }

  for likelihood in placeLikelihoods.likelihoods {
    if let likelihood = likelihood as? GMSPlaceLikelihood {
      let place = likelihood.place
      print("Current Place name \(place.name) at likelihood \(likelihood.likelihood)")
      print("Current Place address \(place.formattedAddress)")
      print("Current Place attributions \(place.attributions)")
      print("Current PlaceID \(place.placeID)")
    }
  }
})

关于似然值的注释:

Notes about the likelihood values:

可能性提供了该地点是 在单个请求的返回地点列表中最匹配. 您无法比较不同请求之间的可能性.的价值 可能性在0到1.0之间.可能性的总和 返回的GMSPlaceLikelihood对象数组中的值始终小于 或等于1.0.请注意,总和不一定是1.0.例如, 代表正确的位置是A位置的55%可能性,以及 位置B的可能性为35%,可能性阵列有两个 成员:地点A的可能性为0.55,地点B的可能性为0.5 可能性为0.35.

The likelihood provides a relative probability of the place being the best match within the list of returned places for a single request. You can't compare likelihoods across different requests. The value of the likelihood will be between 0 and 1.0. The sum of the likelihoods in a returned array of GMSPlaceLikelihood objects is always less than or equal to 1.0. Note that the sum isn't necessarily 1.0. For example, to represent a 55% likelihood that the correct place is Place A, and a 35% likelihood that it's Place B, the likelihood array has two members: Place A with a likelihood of 0.55 and Place B with a likelihood of 0.35.

您还可以使用GMSPlacePicker,如果您希望用户有机会选择他们的当前位置,这将对您有很大帮助.

You also have the chance to use GMSPlacePicker, which can help a lot if you want your users to hace a chance to pick their current place.

这篇关于使用CLLocation和/或Mapkit从坐标中查找公司名称信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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