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

Update user location #258

Open
promistrio opened this issue Sep 10, 2018 · 0 comments
Open

Update user location #258

promistrio opened this issue Sep 10, 2018 · 0 comments

Comments

@promistrio
Copy link

How to update user location. In my situation it's not working

<template>
    <Page class="page">
        <ActionBar class="action-bar" title="Карта">
        <NavigationButton text="Go Back" android.systemIcon="ic_menu_back" @tap="$router.push('/home')"/>
        </ActionBar>
        <StackLayout>

        <Button class="btn btn-primary" @tap="addMarker">Добавить устройство</Button>
        
                <Mapbox
                    accessToken=""
                    latitude="46.2"
                    longitude="39.93"
                    mapStyle="streets"
                    zoomLevel="10"
                    showUserLocation="true"
                    disableZoom="false"
                    disableRotation="true"
                    disableScroll="false"
                    disableTilt="false"
                    ref="map"
                    @mapReady="onMapReady($event)">
                </Mapbox>
        </StackLayout>
    </Page>
</template>

<script>
    import Vue from 'nativescript-vue';
    import * as utils from "utils/utils";
    import * as dialogs from "ui/dialogs"

    Vue.registerElement("Mapbox", () => require("nativescript-mapbox").MapboxView)
    //import mapbox from 'nativescript-mapbox';
    //var mapbox = require("nativescript-mapbox");

    //const geoLocation = require("nativescript-geolocation");

    /*    geoLocation.isEnabled().then(enabled => {
            if (!enabled) {
                geoLocation
                    .enableLocationRequest()
                    .then(() => this.showLocation());
            } else {
             //   this.showLocation();
            }
        });*/

    export default {
        data () {
            return { };
        },
        methods: {
            addMarker(){
                var locations;
                locations = this.$refs.map.nativeView.getUserLocation().then(
                      function(userLocation) {
                          userLat = userLocation.location.lat;
                          userLon = userLocation.location.lng;

                          /*dialogs.alert("Широта и долгота").then(()=> {
                              //console.log("Широта и долгота есть:) "+ userLocation.location.lat + " " + userLocation.location.lng);  
                          });*/
                          

                          //console.log("Current user speed: " +  userLocation.speed);
                      }
                  )

                this.$refs.map.nativeView.addMarkers([
                {
                      lat: 46,
                      lng: 40,
                      title: 'One-line title here',
                      subtitle: 'Really really nice location',
                      selected: true, // makes the callout show immediately when the marker is added (note: only 1 marker can be selected at a time)
                      onCalloutTap: function(){console.log("'Nice location' marker callout tapped");}
                  }]
                );
              
             },
            onMapReady(args) {
                /*args.map.addMarkers([
                    {
                        lat: 37.7397,
                        lng: -121.4252,
                        title: "Tracy, CA",
                        subtitle: "Home of The Polyglot Developer!",
                        onCalloutTap: () => {
                            utils.openUrl("https://www.thepolyglotdeveloper.com");
                        }
                    }
                ]);*/

                args.map.trackUser({
                    mode: "FOLLOW_WITH_COURSE", // "NONE" | "FOLLOW" | "FOLLOW_WITH_HEADING" | "FOLLOW_WITH_COURSE"
                    animated: true
                });
            }
        }
    };
</script>

<style scoped></style>

Don't forget about mapbox token

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

1 participant