error:InvalidValueError: setCenter: not a LatLng or LatLngLiteral: in property lat: not a number

前端 未结 4 834
既然无缘
既然无缘 2021-02-05 03:22
function initAutocomplete() {
    var lat=document.getElementById(\'lat\').value;
    var lng=document.getElementById(\'lng\').value;
    console.log(lat);
    console.l         


        
4条回答
  •  没有蜡笔的小新
    2021-02-05 04:02

    Same error, slightly different scenario:

    I kept getting this error (same as the OP) when trying to use the autocompleted lat/lng to update a map:

        var place = autocomplete.getPlace();
        var geo = place.geometry.location;
        loadMapAt(new google.maps.LatLng(geo.lat, geo.lng));
    

    This "one weird trick" fixed it. Replacing the second line with:

        var geo = JSON.parse(JSON.stringify(place.geometry.location));
    

提交回复
热议问题