Mettler
Mettler

Reputation: 41

Google Maps API: error thrown when setting LatLng values

I'm currently trying to use the Google Maps API to display markers at longitude and latitude values stored in the tweet_object object. Here is my code:

    for (i = 0; i < tweet_object.length; i ++) {
        console.log("Latitude for " + i + ": " + tweet_object[i].latitude);
        console.log("Longitude for " + i + ": " + tweet_object[i].longitude);
        if (tweet_object[i].latitude !== 0 && tweet_object[i].longitude !== 0) {
            var myLatLng = {lat: Math.round(tweet_object[i].latitude), long: Math.round(tweet_object[i].longitude)};
            //var myLatLng = {lat: parseFloat(tweet_object[i].latitude), long: parseFloat(tweet_object[i].longitude)};
            console.log("LatLng: " + myLatLng.lat + ", " + myLatLng.long);
            var marker = new google.maps.Marker({
                map: map,
                position: myLatLng
            });
        };
        console.log("Number: " + i);
    }

I'm getting the following output:

Latitude for 3: -54.4333 (from line 2)

Longitude for 3: 3.4000 (from line 3)

LatLng: -54, 3 (from line 7)

InvalidValueError: setPosition: not a LatLng or LatLngLiteral: in property lng: not a number

Latitudes/longitudes are coming in as values with four decimal points, through tweet_object[i].latitude and tweet_object[i]. longitude. I've tried both Math.round and parseFloat (as well as just inputting tweet_object[i]._____) to get them to work, but everything is throwing the same error, that lng is not a number. Thanks to anyone who can suggest why this is happening.

Upvotes: 0

Views: 581

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133360

should be lng not long

var myLatLng = {lat: Math.round(tweet_object[i].latitude), long: Math.round(tweet_object[i].longitude)};

try

var myLatLng = {lat: Math.round(tweet_object[i].latitude), lng: Math.round(tweet_object[i].longitude)};

Upvotes: 2

Related Questions