Moving Map Under the Marker in Mapbox iOS SDK

ios map sdk
mapbox sdk
mobile sdk mapbox
mapbox swift package manager
mapbox examples
mapbox clustering ios
mapbox ios geocoding
mapbox download

I am new in MapBox iOS SDK and I need to add a marker in the center of MGLMapView so that user would be able to move map view under the marker and the marker would be fix on the screen. I also need to get the coordinate of the point in the map that is under the marker. I could not find any method in Mapbox SDK and I have no idea how to do that.

I believe this is quite easy. Add an image of a marker on top of the map to give the visual effect so the user can still scroll around without moving the marker. Then you can get the center coordinates usually quite easily using mapView.centerCoordinate when the user stops scrolling.

Here is the API documentation link for reference

Add a marker symbol | Maps SDK | iOS, This example uses an image to mark a point on the map. Download the image here and add it to your Xcode project. To learn about more ways to add points to a  MapKit, Google Maps SDK Mapbox GL JS, Mapbox Studio: Mapbox GL JS, Mapbox Studio: Can use images Can use text Control Z-index ⚠️ Add multiple layers at, above, or below a specified layer index to control ordering ⚠️ Add multiple layers at, above, or below a specified layer index to control ordering: Drag and drop Core Animation support

I had done something like this in one of my apps

1) Add map to UIViewController

2) Add a Transparent view on top of the map in UIViewController. (May need to set userInteractionEnabled to false. Not sure though!)

3) Add marker image to the Transparent view so that its bottom tip is at the center of the view it is added to.

4) Get center coordinates by using mapView.centerCoordinate

Camera animation | Maps SDK | iOS, Animate camera movement. to learn more about the many other approaches that can be used to manipulate a map's viewport. ViewController. View on GitHub​. Use a symbol layer to add a marker to the map. This example uses an image to mark a point on the map. Download the image here and add it to your Xcode project.. To learn about more ways to add points to a map, see the Markers and annotations guide.

For other people who have this issue too:

let markerImageView = UIImageView(image: UIImage(named: "Orange"))
markerImageView.center = mapView.center
mapView.addSubview(markerImageView)

Adding markers and shapes | Maps SDK | iOS, There are several approaches that can be used to add markers and shapes to a map, each with different trade-offs. Below is an overview of the variety of  Getting started (3) Create a simple map view Dynamically build a map view Support map fragment Dynamic styling (30) Hillshading Add a new layer below labels Add a vector tile source Add a WMS source Show time lapse Adjust a layer's opacity Animate marker position Icon update based on API response Change a layer's color Change a map's language

First steps with the Mapbox Maps SDK for iOS | Help, To center the map on the tapped marker, start by call the -setCamera:animated: method on the MGLMapView to set the  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Moving Map Under the Marker in Mapbox iOS SDK. Hot

Examples | Maps SDK | iOS, Code examples for the Mapbox Maps SDK for iOS. Use a symbol layer to add a marker to the map. Camera animation. Animate camera movement. Using PaintCode and the Mapbox iOS SDK, we can create a workflow for custom markers and interface elements in an app without paying a price in performance or busywork. Building visually rich, geographically-centered applications leads naturally to a focus on small details.

Adding Markers to a Map Reference, Mapbox iOS SDK Reference Adding Markers to a Map Reference. Guides Use this class if you need your markers to be dynamic or animated. For full control of how markers are displayed on a map, consider using our runtime styling APIs. Add markers SpawnOnMap provides an outline of placing custom markers. It uses the Start() function to calculate initial marker positions, then uses Update() to update those positions every time the map changes (either from zooming or panning).

Comments
  • but when I add a marker by addAnnotation on the mapView and then scroll the map, the marker moves with map.
  • Add the marker as a separate view above the MGLMapView, not as an annotation of the MGLMapView. Then just add constraints to keep the top view centered over the MGLMapView underneath it.
  • @MarkThormann thanks for the help clarifying. Yeah the easy way is to not actually add a marker, add a image of a marker on top of the view, then it wouldn't scroll. otherwise you'd need to listen for any pan movement, or try and observe the center value and update the position of an actual marker, but it rarely stays perfectly in position doing it that way, it lags behind and 'wobbles' around the center
  • How would we know that our map stopped moving? And get the center Coordinates? @HastiRanjkesh
  • @HashirSaeed I believe there are delegate methods to show when the map has been scrolled/panned. I haven't used this SDK in a while so I'm not sure of the exact ones but they
  • You can add the marker image directly on top of the map, or add it as a subview. you dont need a transparent view I dont think
  • If so even better. :)
  • @Scriptable Ok, Thank you.
  • How would you do to have the floating marker a little higher than the center of the map on the Y axis? and also get the coordinates of that marker.
  • @GaboRuiz I would suggest you to use annotations on the map view. That would allow you to move the marker around and get the coordinates automatically