Load googlemaps in Jquery

Asked

Viewed 51 times

0

I’m trying to upload a map, only the map won’t 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);
    }
});
}
  • 1

    Any error message ?

  • I’ve already solved it, I forgot to start the map. Thank you!

1 answer

3


To load the map, first you 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();

});

  • Thank you! it worked!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.