Xcode 谷歌地图搜索栏

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14691703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:43:06  来源:igfitidea点击:

Xcode Google Maps Search Bar

iphonexcodegoogle-mapsgoogle-maps-sdk-ios

提问by user1977908

I'm making an iPhone location based app and I'm having trouble with the last aspect of it. I was wondering if anyone knows how to integrate a search bar that correlates with the map that we can use from MKMapView.

我正在制作一个基于 iPhone 位置的应用程序,但在它的最后一个方面遇到了问题。我想知道是否有人知道如何集成一个与我们可以使用的地图相关的搜索栏MKMapView

It's literally a search bar above the map that the user can type in an area and it will take them there.

它实际上是地图上方的一个搜索栏,用户可以在一个区域中输入它,然后将他们带到那里。

Is this possible?

这可能吗?

I've looked around for tutorials but I have only found how to make an app with a map view, annotations and adding callouts.

我四处寻找教程,但我只找到了如何制作带有地图视图、注释和添加标注的应用程序。

采纳答案by Saxon Druce

What you're looking for is geocoding - the process of turning an address in your search bar into a latitude/longitude coordinate, which you can then set the map's position to.

您正在寻找的是地理编码 - 将搜索栏中的地址转换为纬度/经度坐标的过程,然后您可以将地图的位置设置为该坐标。

This questionhas two main answers. This answershows how to geocode using a Google API, and this answershows how to geocode using an Apple API.

这个问题有两个主要答案。这个答案展示了如何使用 Google API 进行地理编码,这个答案展示了如何使用 Apple API 进行地理编码。

If you're using MapKit (which uses Apple maps as of iOS 6.0), then you should probably use the Apple API (you are not supposed to use Google Maps APIs with non-Google maps).

如果您使用 MapKit(从 iOS 6.0 开始使用 Apple 地图),那么您可能应该使用 Apple API(您不应该将 Google Maps API 与非 Google 地图一起使用)。

If you're using the new Google Maps SDK for iOS, you might want to use the Google API for geocoding. Although note that the answer I've linked to is using the Google API with MapKit (as it was written back when MapKit was using Google Maps), so you would need to modify it a bit.

如果您使用的是适用于 iOS新 Google Maps SDK,您可能希望使用 Google API 进行地理编码。尽管请注意,我链接到的答案是将 Google API 与 MapKit 一起使用(因为它是在 MapKit 使用 Google 地图时写回的),因此您需要对其进行一些修改。