Is the Current Location/Compass Heading Button Available in the iOS Sdk

Is the Current Location/Compass heading button available in the iOS sdk?

You need to create a MKUserTrackingBarButtonItem and pass it the MKMapview in the constructor, then add that button item to the navigation menu (or where ever it is your button should be).

- (void)viewDidLoad
{
[super viewDidLoad];
MKUserTrackingBarButtonItem *buttonItem = [[MKUserTrackingBarButtonItem alloc] initWithMapView:self.map];
self.navigationItem.rightBarButtonItem = buttonItem;
}

Is there a default button for showing the current location in GMSMapView sdk

Yes there is a default button to show current location of map. It will be only visible when you set myLocationEnable in the API.

From the documentation

Google Map SDK for iOS

By default, no location data is shown on the map. You may enable the blue "My Location" dot and compass direction by setting myLocationEnabled on GMSMapView.

mapView_.myLocationEnabled = YES;

Enabling this feature will also provide the user's current location through the myLocation property. This property may not be immediately available - for example, if the user is prompted by iOS to allow access to this data. It will be nil in this case.

NSLog(@"User's location: %@", mapView_.myLocation);

iOS iPhone show user direction and orientation in space like the compass app on MKMapView

I faced a similar situation. I don't think we have library or settings to display the direction on the blue icon (at least my search was not successful).

However it is not difficult to create our own direction indicator using the CLHeading (reference in TommyG's answer).

What I did was to display the blue icon as in the map and provide a small arrow in a different view to indicate the direction.

Hope this helps in some way

Current location button on ios MKMapView

- (void)viewDidLoad
{
[super viewDidLoad];
MKUserTrackingBarButtonItem *buttonItem = [[MKUserTrackingBarButtonItem alloc] initWithMapView:self.map];
self.navigationItem.rightBarButtonItem = buttonItem;
}

Calculating heading of compass to a specific coordinate instead of to north

double lon = location.longitude - otherLocation.longitude;
double y = sin(lon) * cos(otherLocation.latitude);
double x = cos(location.latitude) * sin(otherLocation.latitude) - sin(location.latitude) * cos(otherLocation.latitude) * cos(lon);
double angle = atan2(y, x);

angle is the bearing between the two locations.

Mapbox default compassView when repositioned gives weird outcome

Hey I found another method where I will get the same result of the compass in the map box. I've placed a button and then

func mapViewRegionIsChanging(_ mapView: MGLMapView) {
compassViewUpdate(direction: Double(bearing))

inside compassViewUpdate method

func compassViewUpdate(direction:Double) {

self.compassButton.transform = CGAffineTransform(rotationAngle: CGFloat(-direction.degreesToRadians))
}

@Sarang here is a work around. Happy coding.

Is there any default button for mapKit to allow user to change the orientation of the map from device heading to North up?

Yes, there is a button named MKUserTrackingButton. (You can read more about it here)

To implement it, you should set userTrackingMode property. (See more)

It is available on iOS11.0+, so it should do the job.

How to Show my current location on google maps, when I open the ViewController? in Swift?

For Swift 3.x solution, please check this Answer

First all of you have to enter a key in Info.plist file
NSLocationWhenInUseUsageDescription

Sample Image

After adding this key just make a CLLocationManager variable and do the following

@IBOutlet weak var mapView: GMSMapView!
var locationManager = CLLocationManager()

class YourControllerClass: UIViewController,CLLocationManagerDelegate {

//Your map initiation code
let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
self.view = mapView
self.mapView?.myLocationEnabled = true

//Location Manager code to fetch current location
self.locationManager.delegate = self
self.locationManager.startUpdatingLocation()
}

//Location Manager delegates
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

let location = locations.last

let camera = GMSCameraPosition.cameraWithLatitude((location?.coordinate.latitude)!, longitude: (location?.coordinate.longitude)!, zoom: 17.0)

self.mapView?.animateToCameraPosition(camera)

//Finally stop updating location otherwise it will come again and again in this delegate
self.locationManager.stopUpdatingLocation()

}

When you run the code you will get a pop up of Allow and Don't Allow for location. Just click on Allow and you will see your current location.

Make sure to do this on a device rather than simulator. If you are using simulator, you have to choose some custom location and then only you will be able to see the blue dot.

Sample Image



Related Topics



Leave a reply



Submit