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

draw the user trip #268

Closed
epileftro85 opened this issue Oct 12, 2018 · 4 comments
Closed

draw the user trip #268

epileftro85 opened this issue Oct 12, 2018 · 4 comments
Milestone

Comments

@epileftro85
Copy link

Hi, i want to draw the user's trip with the gps on real time, i have been trying with track user, but it just fallow the user but not give me the coordinates, i also tried with getUserLocation with no success, there is a way to accomplish this?

@EddyVerbruggen
Copy link
Collaborator

Can you share a repo showing getUserLocation doesn't work? If so, that's a bug.

@epileftro85
Copy link
Author

yes sure, here is the Repo

EddyVerbruggen added a commit that referenced this issue Oct 15, 2018
@EddyVerbruggen EddyVerbruggen added this to the 4.4.0 milestone Oct 15, 2018
@EddyVerbruggen
Copy link
Collaborator

@epileftro85 Thanks for the repo! I've updated the Mapbox Android SDK and was able to get it working on your repo by delaying tracking a bit (because you can't track unless the location is already shown on the map).

So bump the plugin to 4.4.0, and replace map.component.ts by this:

import { Component, OnInit } from "@angular/core";
import { MapboxViewApi } from "nativescript-mapbox";

import * as geolocation from "nativescript-geolocation";
import { Accuracy } from "ui/enums";

@Component({
  selector: "Map",
  moduleId: module.id,
  templateUrl: "./map.component.html"
})
export class MapComponent implements OnInit {
  private lat_value: number = 0;
  private lng_value: number = 0;
  private map: MapboxViewApi;
  private watchId: any = null;

  constructor() {
    /************************************************************
     * Use the constructor to inject app services that you need in this component.
     *************************************************************/
  }

  ngOnInit(): void {
    var that = this;

    // get geolocation permitted
    if (!geolocation.isEnabled()) {
      geolocation.enableLocationRequest();
    }

    // get current location
    var location = geolocation
        .getCurrentLocation({
          desiredAccuracy: Accuracy.high,
          updateDistance: 10,
          maximumAge: 20000,
          timeout: 20000
        })
        .then(
            function (loc) {
              if (loc) {
                console.log(
                    "Current location is: " + loc.latitude + ", " + loc.longitude
                );
                that.lat_value = loc.latitude;
                that.lng_value = loc.longitude;
              }
            },
            function (e) {
              console.log("Error: " + e.message);
            }
        );
  }

  onMapReady(args): void {
    this.map = args.map;

    // wait until the location is showing on the map
    setTimeout(() => {
      this.map.trackUser({mode: "FOLLOW_WITH_HEADING", animated: true})
          .then(() => console.log("tracking"))
          .catch(err => console.log("tracking error: " + err));
    }, 2000);

    this.map.getUserLocation().then(userLocation => {
      console.log(
          "Current user location: " +
          userLocation.location.lat +
          ", " +
          userLocation.location.lng
      );
      console.log("Current user speed: " + userLocation.speed);
    });
  }
}

@epileftro85
Copy link
Author

Hi, thanks for the reply, i can't make it work, would you please tell me how do you test it?, i am trying to testing with the iOS simulator with the bike route, but it just console log the first point, after that it just doesn't show any output, i want to save the location every 2 sec in a file, but if i can't get those values i can't save anything, sorry for troubles, thanks in advance

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

No branches or pull requests

2 participants