Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

309
Views
Why can't I use a variable in html... vue js

I get information about location, but can not use it in html.error => Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'geoLocationPlace').Why is the variable(geoLocationPlace)undefined?

 data() {
        return {
            inputValue:null,
            searchedPlace:null,
            geoLocationPlace:null,
        }
    },

          getLocation(){
            if(navigator.geolocation){
                navigator.geolocation.getCurrentPosition(function(position){
                    let long = position.coords.longitude;
                    let lat = position.coords.latitude;
                    
                    fetch(`https://api.bigdatacloud.net/data/reverse-geocode-client? 
                               latitude=${lat}&longitude=${long}&localityLanguage=en`)
                    .then(res => {
                        return res.json()
                    })
                    .then(resData => {
                        //resData.countryName return country
                        this.geoLocationPlace = resData.countryName
                        console.log(this.geoLocationPlace)
                    })
                    
                })
            
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The issue is that this is "lost" because you use a regular function as the callback to navigator.geolocation.getCurrentPosition

You clearly understand the need for arrow functions, as your fetch chain uses them, so I can only conclude that you simply missed this function

getLocation(){
  if(navigator.geolocation){
    // fix the next line like so
    navigator.geolocation.getCurrentPosition((position) => {
      let long = position.coords.longitude;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!