question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to enable Show Location button?

See original GitHub issue

Hi,

I am wondering how to enable the Location Button on my map (bottom right): http://imgur.com/R1KFUtJ

BTW animateToLocation method of the gMap object throws error when executed:

mapView.gMap.animateToLocation();

which resulted in app crash.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
Stavanger75commented, Jul 4, 2016

Hi,

I got this code to work on android and ios. Hope it helps.

   mapView = args.object;
    var gMap = mapView.gMap;

    if(mapView.android) {
        uiSettings = gMap.getUiSettings();
        uiSettings.setMyLocationButtonEnabled(true);
        gMap.setMyLocationEnabled(true);
    }

    if (mapView.ios) {
        gMap.myLocationEnabled = true;
        gMap.settings.myLocationButton = true;
    }

Here is a more complete sample. (not tested). Sorry for the bad formating of the code under.

//Plugin from : https://github.com/NathanaelA/nativescript-permissions var permissions = require('nativescript-permissions');

exports.onMapReady(args){

        mapView = args.object;
        var gMap = mapView.gMap;
//Application request the location permission
    permissions.requestPermission(android.Manifest.permission.ACCESS_FINE_LOCATION, "I need these permissions because I'm cool")
        .then(function() {
                    console.log("Woo Hoo, I have the power!");
                    if(mapView.android) {
                    uiSettings = gMap.getUiSettings();
                    uiSettings.setMyLocationButtonEnabled(true);
                        gMap.setMyLocationEnabled(true);
                }

                if(mapView.ios) {
                        gMap.myLocationEnabled = true;
                        gMap.settings.myLocationButton = true;
            }

      })
       .catch(function() {
            console.log("Uh oh, no permissions - plan B time!");
        });

}

1reaction
ickatacommented, Jul 5, 2016

I confirm that the example is working on my side.

Thanks, @Stavanger75 !

Read more comments on GitHub >

github_iconTop Results From Across the Web

LocationButton | Apple Developer Documentation
LocationButton simplifies requesting one-time authorization to access location data. Add this button to your SwiftUI user interface in situations when users may ...
Read more >
Using the new location button to access your user's GPS ...
With iOS 15 and watchOS 8, Apple is now introducing LocationButton , a SwiftUI view that gives your app access to the user's...
Read more >
How to Implement Current Location Button Feature in Google ...
Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for...
Read more >
A better way to ask for a one-time user's location with ... - Sarunw
Normally, the location permission popup won't show again if the user selects the "Don't Allow" option, but that isn't the case for the...
Read more >
Can't see my current location, the location button doesn't appear
You can use the My Location layer and the My Location button to provide your user with their current position on the map....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found