Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda