Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

birdietorerik's avatar

How to get access to my position web browser iphone

Hi!

Have created a wepage laravel8.x / vue That gives me my position

Working fine localy, but not when i start my webpage on my server

Get this error message on my iphone:

 no position access

My vue page

<template>
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
                <h2>Min posisjon:</h2>
                <p style="color:white;">{{ myCoordinates.lat }} Latitude, {{ myCoordinates.lng }} Longitude</p>
            </div>
            <div class="col-md-12">
                <h2>Map coordinates:</h2>
                <p style="color:white;">{{ mapCoordinates.lat }} Latitude, {{ mapCoordinates.lng }} Longitude</p>
            </div>
        </div>
       
       
    </div>
</template>
<script>
    export default {
        data() {

            return {
                myCoordinates: {
                    lat: 0,
                    lng: 0
                },
                zoom: 10
            }
        },
        created() {
            // does the user have a saved center? use it instead of the default
            if(localStorage.center) {
                let center = JSON.parse(localStorage.center);
                this.myCoordinates = {
                    lat: parseFloat(center.lat),
                    lng: parseFloat(center.lng)  
                }
            } else {
                // get user's coordinates from browser request
                this.$getLocation({})
                    .then(coordinates => {
                        this.myCoordinates = coordinates;
                    })
                    .catch(error => alert(error));
            }
            // does the user have a saved zoom? use it instead of the default
            if(localStorage.zoom) {
                this.zoom = parseInt(localStorage.zoom);
            }
        },
        
        methods: {
            handleDrag() {
                // get center and zoom level, store in localstorage
                console.log("handleDrag");

                let center = {
                    lat: this.map.getCenter().lat().toFixed(4),
                    lng: this.map.getCenter().lng().toFixed(4)
                };
                console.log(center.lat);
                let zoom = this.map.getZoom();
                localStorage.center = JSON.stringify(center);
                localStorage.zoom = zoom;
            }
        },
        computed: {
            mapCoordinates() {
                if(!this.map) {
                    console.log("MAPCOORDINATES"); 
                    return {
                        lat: 0,
                        lng: 0
                        
                    };
                }
                console.log("mapCoordinates HER");
                return {
                    lat: this.map.getCenter().lat().toFixed(4),
                    lng: this.map.getCenter().lng().toFixed(4)
                }
            }
        }
    }
</script>

How can i get access, to get my possition ?

0 likes
16 replies
martinbean's avatar

@birdietorerik Then it’s not going to work.

Asking for sensitive information like the user’s geographical position is opt-in. An app has to ask permission using the browser APIs, and a user has to explicitly approve the request to share their location with a web page, before that web page can start doing things with that information.

If the browser doesn’t support geolocation, or the user has declined the request, then your app won’t get the coordinates.

birdietorerik's avatar
birdietorerik
OP
Best Answer
Level 8

@martinbean Hi! Think the problem is rhat it dosent ask for permission to use geolocation. If It do that, it will work

Sinnbeck's avatar

@birdietorerik make a button and have it trigger this. Then you can see if it works

navigator.permissions.query({name:'geolocation'}).then(function(result) {
    alert(result.state);
});
Tray2's avatar

@birdietorerik In your setting you can allow or disallow location tracking on the iPhone. It can be found under integrity location something.

mabdullahsari's avatar

Weird decision to star an unsolved thread, but OK. I will assume the best.

You can get geo info if the browser supports it, otherwise you can't use it. This means that you have to do some feature detection if you want to support ancient browsers.

birdietorerik's avatar

@Sinnbeck tryed it in chrome, safari , edge… I think the problem is that it dosent ask user for permission to use your position ?

Sinnbeck's avatar

@birdietorerik you should get a pop-up asking for permission. It works on my phone (android) in both Firefox and Chrome

martinbean's avatar

Tryed the button there And get error: PERMISSION_DENIED – User denied Geolocation.

@birdietorerik Then you’ve previously denied the request to allow geocoding.

Please or to participate in this conversation.