Upload googlemaps in JQuery

0

I'm trying to load a map, but the map does not boot.

The code I use to load the map:

function carregaMapa(endereco) {
var address = endereco;
geocoder.geocode({ 'address': address }, function (results, status) {
    if (status == 'OK') {
        map.setCenter(results[0].geometry.location);
        map.setZoom(16);
        var marker = new google.maps.Marker({
            map: map,

            position: results[0].geometry.location

        });
    } else {
        alert('Geocode was not successful for the following reason: ' + status);
    }
});
}
    
asked by anonymous 27.06.2018 / 02:52

1 answer

3

To load the map, you first need to initialize the map, try using the code below:

function iniciaMapa() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
    zoom: 8,
    center: latlng
}
map = new google.maps.Map(document.getElementById('map'), mapOptions);

}

and then

$(document).ready(function () {
iniciaMapa();

});

    
27.06.2018 / 02:57