【问题标题】:Searching for location by name in Instagram API在 Instagram API 中按名称搜索位置
【发布时间】:2018-03-19 12:57:41
【问题描述】:

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

有没有办法让它像 Instagram 应用程序本身一样,通过输入名称来搜索位置?

谢谢!

【问题讨论】:

    标签: ios swift location instagram-api


    【解决方案1】:

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

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

    【讨论】:

    • 抱歉,这不是我要找的,这意味着我需要使用 2 个端点,第一个获取位置,然后使用 Instagram 一个通过 lat 确定位置我从以前的搜索中得到了很长时间。你知道我只需要调用一个端点就可以做到吗?
    • 不是在我的脑海中,但我会在有时间的时候通读 API,如果我找到你正在寻找的东西,我会回到这个线程。
    猜你喜欢
    • 2014-04-22
    • 1970-01-01
    • 1970-01-01
    • 2017-11-17
    • 2020-05-05
    • 1970-01-01
    • 1970-01-01
    • 2016-05-24
    • 1970-01-01
    相关资源
    最近更新 更多