Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

310
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda