In the Here iOS SDK, how can I make an NMAMapMarker show a callout when tapped?

白昼怎懂夜的黑 提交于 2019-12-08 05:00:45

问题


I'm building an iOS app that includes Here map & search features, and I'm currently using the "starter" SDK. Currently, when the app performs a search, an NMAMapMarker is created for each search result. I'd like the map display some kind of callout or information box when the user taps on a MapMarker (like what happens when you tap a pin in Apple Maps), but I can't figure out if this feature is included in the SDK.

I know there's a didSelectObject delegate method, but do I have to create a custom view and manually present it? I also noticed that the "Premium" SDK includes an NMAMapOverlay. Is this a better option for displaying info boxes when being tapped? And finally, I noticed in the inheritance diagram of NMAView (https://developer.here.com/mobile-sdks/documentation/ios-hybrid-plus/topics_api_nlp_hybrid_plus/interfacenmaviewobject.html) there's an NMALabledMapMarker, but I can't find anything else about it in the API reference. Would this be a good way to show some basic information about a place on a MapMarker? What's the best way to show basic info about a place on a Here map?


回答1:


The NMAMapOverlay is the only option right now. This functionality is only provided within the HERE SDK for iOS Premium.




回答2:


You have a right start.

I suppose you have an array of coordinates which you add as NMAMapMarkers on the NMAMapView.

So basically every NMAMapMarker has it's own coordinates from where you can distinguish it from others.

After you conform to NMAMapViewDelegate, use this method:

func mapView(_ mapView: NMAMapView, didSelect objects: [NMAViewObject]) {
  for object in objects {
     // Search for NMAMapMarkers only
     if object is NMAMapMarker {
          // Get your map marker as follow
          let mapMarker = object as! NMAMapMarker
          // Check if you found your map marker by checking coordinates
          // Show desired information with your custom method
          }
      }
   }
}

Notice: NMAMapOverlay doesn't have any tap detect method which is provided be Here Maps SDK. You have to implement it on your own. Since NMAMapOverlay inherits from Apple's UIView it allows you to do that.

It's yours to choose between them, based on your needs.

I would say, go with NMAMapMarker




回答3:


Currently, NMAMapOverlay is the only option to display custom view in place of NMAMapMarkers.

NMAMapOverlay* overlaySubview = [NMAMapOverlay mapOverlayWithSubview:customView geoCoordinates:place.position];

[self.mapView addMapOverlay:overlaySubview];



来源:https://stackoverflow.com/questions/31272385/in-the-here-ios-sdk-how-can-i-make-an-nmamapmarker-show-a-callout-when-tapped

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!