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

160
Views
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 answers
Answer question

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 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!