ShowUserLocation not working
See original GitHub issueHi.
I cannot get the user location shown on the map properly. Is there anything that I am missing right now?
import {Component, OnInit} from "@angular/core";
import {Page} from "ui/page";
var mapbox = require("nativescript-mapbox");
var geolocation = require("nativescript-geolocation");
const accessToken: string = "...";
@Component({
selector: "my-app",
templateUrl: "app.component.html"
})
export class AppComponent implements OnInit {
constructor(private page: Page) {
this.page.actionBarHidden = true;
}
ngOnInit() {
var that = this;
// get geolocation permitted
if (!geolocation.isEnabled()) {
geolocation.enableLocationRequest();
}
mapbox.hasFineLocationPermission().then(
function(granted) {
// if this is 'false' you probably want to call 'requestFineLocationPermission' now
console.log("Has Location Permission? " + granted);
});
// if no permission was granted previously this will open a user consent screen
mapbox.requestFineLocationPermission().then(
function() {
console.log("Location permission requested");
}
);
// get current location
var lat_value = 0; var lng_value = 0;
var location = geolocation.getCurrentLocation({desiredAccuracy: 3, updateDistance: 10, maximumAge: 20000, timeout: 20000}).
then(function(loc) {
if (loc) {
console.log("Current location is: " + loc.latitude + ", " + loc.longitude);
lat_value = loc.latitude;
lng_value = loc.longitude;
}
}, function(e){
console.log("Error: " + e.message);
}).
then(function() {
// display the map for curr
setTimeout(() => {
that.show_map(lat_value, lng_value);
}, 100);
}
);
}
show_map(latitude, longitude) {
mapbox.show({
accessToken: accessToken,
style: mapbox.MapStyle.OUTDOORS,
margins: {
left: 30,
right: 30,
top: 30,
bottom: 30
},
showUserLocation: true, // default false
center: {
lat: latitude,
lng: longitude
},
zoomLevel: 14, // 0 (most of the world) to 20, default 0
hideAttribution: true, // default false
hideLogo: true, // default false
hideCompass: false, // default false
disableRotation: false, // default false
disableScroll: false, // default false
disableZoom: false, // default false
disableTilt: false, // default false
}).then(
function(result) {
console.log("Mapbox show done");
},
function(error) {
console.log("mapbox show error: " + error);
}
);
}
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:8
Top Results From Across the Web
React Native Maps - showsUserLocation not working
You need to set your location in the simulator > Features > Location > Custom Location settings to be able to see your...
Read more >showsUserLocation doesnt work on Android #2747 - GitHub
Showing user location works out-of-the-box on iOS but not on Android. I found a workaround to ask for permissions using PermissionsAndroid ...
Read more >showsUserLocation | Apple Developer Documentation
A Boolean value that indicates whether the map tries to display the user's location. iOS 3.0+ iPadOS 3.0+ macOS 10.9+ ...
Read more >MKMapView .ShowsUserLocation - not displaying blue dot
I'm running in the stable channel. I went through the process of updating to the Unified API on Monday. I'm getting a report...
Read more >How to show a Map view - a free SwiftUI by Example tutorial
Finally, you can ask the map to show the user's location – and even follow them as they move – by providing values...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oh wow, that icon may come in handy if the version I just pushed is flaky. The advantage of the current version is though that the plugin uses icons bundled with the Mapbox SDK.
Available in 2.2.0 which is now on GitHub and very soon on npm as well.
Ha, lol, I’ve just replicated that UI by manually adding 2 markers one the same spot (my location) using those blue and white drawables. So I guess I can release a good v1 based on that approach tomorrow. Thx!