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

162
Visualizações
variable in Jquery For Google Map

I have ajax success function like below

success: function(result) {

    for (var i = 0; i < result['Result'].length; i++) {

        if (result['Result'][i]['ClusterId'] == '2414040001') {
            if (result['Result'][i]['UserLatitude'] != '' &&
                result['Result'][i]['UserLatitude'] != null) {
                window.UserLatitude = result['Result'][i][
                    'UserLatitude'
                ];
            } else {
                window.UserLatitude = '';
            }

            if (result['Result'][i]['UserLongitude'] != '' &&
                result['Result'][i]['UserLongitude'] != null) {
                window.UserLongitude = result['Result'][i][
                    'UserLongitude'
                ];
            } else {
                window.UserLongitude = '';
            }

            console.log("LAT:" + UserLatitude + "LONG:" +
                UserLongitude);
        }


    }


    const myLatLng = {
        lat: UserLatitude,
        lng: UserLongitude
    };
    console.log(myLatLng);
    const map = new google.maps.Map(document.getElementById(
        "googleMap"), {
        zoom: 4,
        center: myLatLng,
    });

    new google.maps.Marker({
        position: {
            lat: -33.890,
            lng: 151.274
        },
        map,
        title: "Hello World!",
    });




}

I am getting latitude and longitude from remote server and want use it for Google Map. Its working fine if I use const like below

const myLatLng = { lat: -33.890, lng: 151.274 };

but if I use variable for it, its giving me error like below

InvalidValueError: setCenter: not a LatLng or LatLngLiteral with finite coordinates: in property lat: not a number

I am not getting idea what is the problem and how I can solve it.

Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The response returned by the server might be string.Can you please try this code to parse the lat and long value to float lat and lng value using parseFloat() method from javascript.

// const myLatLng = { lat: UserLatitude, lng: UserLongitude };
// change above code to 
const myLatLng = { lat: parseFloat(UserLatitude), lng: parseFloat(UserLongitude) };
                  console.log(myLatLng);
                  const map = new google.maps.Map(document.getElementById("googleMap"), {
                    zoom: 4,
                    center: myLatLng,
                  });
                
                  new google.maps.Marker({
                    position: {lat: -33.890, lng: 151.274},
                    map,
                    title: "Hello World!",
                  });

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