简体   繁体   中英

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

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?

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

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

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM