ios - 在 Instagram API 中按名称搜索位置

标签 ios swift location instagram-api

我正在使用适用于 iOS 的 Instagram API。我想按名称搜索位置,就像在 Instagram 应用程序本身中一样,但可用于搜索位置的唯一端点是按 LAT 和 LONG。

有没有一种方法可以像 Instagram 应用程序本身一样,通过输入名称来搜索位置?

谢谢!

最佳答案

我做过类似的事情,但我必须自己编写代码。我使用 searchBar 获取位置并将该位置作为 注释 固定到 MapView 我使用了 注释坐标来执行搜索。我故意展示 map 和图钉。这是我使用的代码。

         // do search for locations 
         localSearchRequest = MKLocalSearchRequest() 
         localSearchRequest.naturalLanguageQuery = searchBar.text 
         localSearch = MKLocalSearch(request: localSearchRequest) 
         localSearch.start { (localSearchResponse, error) -> Void in 


             // alert if location not found 
             if localSearchResponse == nil{ 
                 let alertController = UIAlertController(title: nil, message: "Place Not Found", preferredStyle: UIAlertControllerStyle.alert) 
                 alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.default, handler: nil)) 
                 self.present(alertController, animated: true, completion: nil) 
                 activityIndicator.hide() 
                 return 
             } 

             // append annotation if result is found 
             self.pointAnnotation = MKPointAnnotation() 
             self.pointAnnotation.title = searchBar.text 
             // get pin location 
             self.pointAnnotation.coordinate = CLLocationCoordinate2D(latitude: localSearchResponse!.boundingRegion.center.latitude, longitude:     localSearchResponse!.boundingRegion.center.longitude) 


             self.pinAnnotationView = MKPinAnnotationView(annotation: self.pointAnnotation, reuseIdentifier: nil) 
             self.mapView.centerCoordinate = self.pointAnnotation.coordinate 


             self.mapView.addAnnotation(self.pinAnnotationView.annotation!) 

如果您不打算使用mapView,您仍然可以使用此代码来获取位置纬度和经度

let location = CLLocationCoordinate2D(latitude:
                       localSearchResponse!.boundingRegion.center.latitude,
                       longitude: localSearchResponse!.boundingRegion.center.longitude)

关于ios - 在 Instagram API 中按名称搜索位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49363575/

相关文章:

java - Android 地磁场不工作

swift - 关于ARC,下面的代码中Kraken是否强引用了Sucker?

ios - 从 MPRemoteCommandCenter 丢失 "Now Playing"状态

ios - 如何自定义单元格的一部分

java - JFrame 未出现在鼠标单击位置(包括 SSCCE)

ios - 检查 JSON 中的空数组

ios - 优化字符串解析

android - UIView 的水平滚动就像 Android 中的 IOS 概念

ios - 即使 EKEvent.hasNotes 返回 YES,EKEvent.notes 也会返回 (null)

android - getLastKnownLocation 不适用于 Samsung Galaxy S3 4.0.4