Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to enable Show Location button? #44

Closed
ickata opened this issue Jul 1, 2016 · 8 comments
Closed

How to enable Show Location button? #44

ickata opened this issue Jul 1, 2016 · 8 comments

Comments

@ickata
Copy link

ickata commented Jul 1, 2016

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.

@dapriett
Copy link
Owner

dapriett commented Jul 1, 2016

I believe you enable my location

function onMapReady(args) {
    var mapView = args.object;
    var gMap = mapView.gMap;

    if(mapView.android) {
        gMap.setMyLocationEnabled(true);
    }

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

@ickata
Copy link
Author

ickata commented Jul 2, 2016

Not exactly. This is how I enable it:

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

In iOS myLocationEnabled is a property (Boolean), not a method.

Also this only shows the blue dot where your location is. What I want is to display the button at the bottom-right corner, which when pressed moves the map camera to your location. I am sure that this is possible with GMaps API since there is another nativescript-googlemaps plugin which does this by default. But your plugin has more rich API :)

@Stavanger75
Copy link

+1

@Stavanger75
Copy link

Stavanger75 commented 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!");
        });

}

@ickata
Copy link
Author

ickata commented Jul 5, 2016

I confirm that the example is working on my side.

Thanks, @Stavanger75 !

@elpin1988
Copy link

How I do add input autocomplete directions to mapview with angular and typescript on nativescript?

@Aks659
Copy link

Aks659 commented Sep 19, 2017

@Stavanger75 .
For me mapView.android is throwing error.
So, I am using platform.isAndroid instead.

@MrSinaRJ
Copy link

MrSinaRJ commented Nov 7, 2017

I got the map working like mentioned by @Stavanger75 , BUT something very weird is going on here!

ActivityManager: Start proc 25860:org.nativescript.MapTest/u0a298 for activity org.nativescript.MapTest/com.tns.NativeScriptActivity
JS: Woo Hoo, I have the power!
JS: Uh oh, no permissions - plan B time!

how is that possible that console.log prints .then and .catch body!!!!
Am i missing something or something is wrong here?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants