How to fix Uncaught InvalidValueError: setPosition: not a LatLng or LatLngLiteral: in property lat: not a number?

后端 未结 9 736
天命终不由人
天命终不由人 2020-12-13 17:14

I\'m trying to port my googlemaps v2 functions to v3.

But somehow i stuck in a strange error and i could not find, what i\'m doing wrong.

Erro

9条回答
  •  失恋的感觉
    2020-12-13 17:48

    I had the same problem when setting the center of the map with map.setCenter(). Using Number() solved for me. Had to use parseFloat to truncate the data.

    code snippet:

     var centerLat = parseFloat(data.lat).toFixed(0);
     var centerLng = parseFloat(data.long).toFixed(0);
     map.setCenter({
          lat: Number(centerLat),
          lng: Number(centerLng)
     });
    

提交回复
热议问题