“SetCenter: no un latlng o latlngliteral con coordenadas finitas: en la propiedad Lat: no un número” Código de respuesta

SetCenter: no un latlng o latlngliteral con coordenadas finitas: en la propiedad Lat: no un número

70

The .value attribute of a HTMLInputElement returns the value as a string.

You have to parse the content of lat and lng with parseFloat() before passing it to the maps API

function initAutocomplete() {
    var lat = parseFloat(document.getElementById('lat').value);
    var lng = parseFloat(document.getElementById('lng').value);

    var map = new google.maps.Map(document.getElementById('map'), {
        center: {
            lat: lat,
            lng: lng
        },
        zoom: 13,
        mapTypeId: 'roadmap'
    });
}
shafeeque

SetCenter: no un latlng o latlngliteral con coordenadas finitas: en la propiedad Lat: no un número

//The error comes because you pass the value as string:
var lat = document.getElementById('lat').value;

//you need to set it as float:
var lat = parseFloat(document.getElementById('lat').value);
Ivan The Terrible

Respuestas similares a “SetCenter: no un latlng o latlngliteral con coordenadas finitas: en la propiedad Lat: no un número”

Preguntas similares a “SetCenter: no un latlng o latlngliteral con coordenadas finitas: en la propiedad Lat: no un número”

Más respuestas relacionadas con “SetCenter: no un latlng o latlngliteral con coordenadas finitas: en la propiedad Lat: no un número” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código