ios – 如何访问MKMapItem的类别或类型

ios – 如何访问MKMapItem的类别或类型,第1张

概述我正在编写一个使用MapKit的应用程序.我已经实现了MKLocalSearch,我得到了一个MKMapItem数组.但是我想知道是否可以获得这些项目的类别.例如,在地图应用程序中,为商店,酒店,火车站等显示了不同的图标.此外,如果您查看地点标记.您将获得一个类别标签,如Grocery.作为开发人员,我可以访问Map项目的信息吗?如果是这样,我想知道如何. 谢谢 是的,您可以获得此信息.有关搜索位 我正在编写一个使用MapKit的应用程序.我已经实现了MKLocalSearch,我得到了一个MKMAPItem数组.但是我想知道是否可以获得这些项目的类别.例如,在地图应用程序中,为商店,酒店,火车站等显示了不同的图标.此外,如果您查看地点标记.您将获得一个类别标签,如Grocery.作为开发人员,我可以访问Map项目的信息吗?如果是这样,我想知道如何.

谢谢

解决方法 是的,您可以获得此信息.有关搜索位置的详细信息,请参阅以下方法.

我担心您只能从MKPlacemark获取地址详细信息.

现在您需要做的是,从MKPlacemark获取地址详细信息,您需要获得任何开源API的帮助,这些API可以帮助您将地址分类为某些标签/注释.

其中一个很好的API是Mapbox,但遗憾的是它已付费.

因此,从第三方API,您可以进行神​​奇的搜索.我没有搜索API / WebService,但它应该在那里.

目标C代码:

- (voID) searchForPlace:(Nsstring *) keyWord {    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];    MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init];    request.naturalLanguagequery = keyWord; // @"restaurant"    MKCoordinateSpan span = MKCoordinateSpanMake(.1,.1);    CLLocationCoordinate2D location = self.mapVIEw.centerCoordinate;    request.region = MKCoordinateRegionMake(location,span);    MKLocalSearch *search = [[MKLocalSearch alloc] initWithRequest:request];    [search startWithCompletionHandler:     ^(MKLocalSearchResponse *response,NSError *error) {         [self.txtSearch setEnabled:YES];         [self removeMapOverlay];         [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];         if (!error) {             // Result found             @try {                 if (response.mAPItems && [response.mAPItems count] > 0) {                     for (MKMAPItem *item in response.mAPItems) {                         MKPlacemark *placeMark = item.placemark;                         // Address details                         NSDictionary *address = placeMark.addressDictionary;                         Nsstring *TitleString = @"";                         Nsstring *subTitleString = @"";                         Nsstring *name = @"";                         Nsstring *Thoroughfare = @"";                         Nsstring *State = @"";                         Nsstring *City = @"";                         Nsstring *Country = @"";                         name = [address objectForKey:@"name"] ? [address objectForKey:@"name"] : @"";                         Thoroughfare = [address objectForKey:@"Thoroughfare"] ? [address objectForKey:@"Thoroughfare"] : @"";                         State = [address objectForKey:@"State"] ? [address objectForKey:@"State"] : @"";                         City = [address objectForKey:@"City"] ? [address objectForKey:@"City"] : @"";                         Country = [address objectForKey:@"Country"] ? [address objectForKey:@"Country"] : @"";                         TitleString = [Nsstring stringWithFormat:@"%@ %@",name,Thoroughfare];                         subTitleString = [Nsstring stringWithFormat:@"%@ %@ %@",State,City,Country];                         CustomAnnotation *annotation = [[CustomAnnotation alloc] initWithTitle:TitleString subTitle:subTitleString detailURL:item.url location:placeMark.location.coordinate];                         [self.mapVIEw addAnnotation:annotation];                     }                     [self mapVIEw:self.mapVIEw regionDIDChangeAnimated:YES];                 }             }             @catch (NSException *exception) {                 NSLog(@"Exception :%@",exception.description);             }         } else {             NSLog(@"No result found.");         }     }];}

SWIFT代码:

func searchForPlace(keyword: String) {    UIApplication.sharedApplication().networkActivityIndicatorVisible = true    var requset = MKLocalSearchRequest()    requset.naturalLanguagequery = keyword    let span = MKCoordinateSpanMake(0.1,0.1)    let region = MKCoordinateRegion(center: self.mapVIEw.centerCoordinate,span: span)    var search = MKLocalSearch(request: requset)    search.startWithCompletionHandler { (var response: MKLocalSearchResponse!,var error: NSError!) -> VoID in        UIApplication.sharedApplication().networkActivityIndicatorVisible = false        if (error != nil) {            // Result found            if (response.mAPItems != nil && response.mAPItems.count > 0) {                for item: MKMAPItem! in response.mAPItems as [MKMAPItem] {                    var placeMark = item.placemark as MKPlacemark!                    // Address details...                    var address = placeMark.addressDictionary as NSDictionary!                    var TitleString: String!                    var subTitleString: String!                    var name: String!                    var Thoroughfare: String!                    var State: String!                    var City: String!                    var Country: String!                    var emptyString: String! = " "                    name = (address.objectForKey("name") != nil ? address.objectForKey("name") : emptyString) as String                    Thoroughfare = (address.objectForKey("Thoroughfare") != nil ? address.objectForKey("Thoroughfare") : emptyString) as String                    State = (address.objectForKey("State") != nil ? address.objectForKey("State") : emptyString) as String                    City = (address.objectForKey("City") != nil ? address.objectForKey("City") : emptyString) as String                    Country = (address.objectForKey("Country") != nil ? address.objectForKey("Country") : emptyString) as String                    TitleString = String(format: "%@ %@",Thoroughfare)                    subTitleString = String(format: "%@ %@ %@",Country)                    var customAnnotation = CustomAnnotation(coordinate: placeMark.location.coordinate,Title: TitleString,subTitle: subTitleString,detailURL: item.url)                    self.mapVIEw.addAnnotation(customAnnotation)                }                self.mapVIEw(self.mapVIEw,regionDIDChangeAnimated: true)            }        }    }}
总结

以上是内存溢出为你收集整理的ios – 如何访问MKMapItem的类别或类型全部内容,希望文章能够帮你解决ios – 如何访问MKMapItem的类别或类型所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1060833.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-25
下一篇2022-05-25

发表评论

登录后才能评论

评论列表(0条)

    保存