Miomir Dancevic
Miomir Dancevic

Reputation: 6852

Google Map API3 return no map?

Im trying to make marker on google map, based on adress, but maps is showing no data?

Here is my example

$(document).ready(function() {

    /* google maps */

    google.maps.visualRefresh = true;
    var geocoder = new google.maps.Geocoder();
    var mapOptions = {
        zoom: 14, // set the zoom level manually
        zoomControl: false,
        scaleControl: false,
        scrollwheel: false,
        disableDoubleClickZoom: true,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };


    var map;

    function initialize() {
        var address = $('#map').text(); /* change the map-input to your address */
        map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

        if (geocoder) {
            geocoder.geocode({
                'address': address
            }, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
                        map.setCenter(results[0].geometry.location);

                        var infowindow = new google.maps.InfoWindow({
                            content: address,
                            map: map,
                            position: results[0].geometry.location,
                        });

                        var marker = new google.maps.Marker({
                            position: results[0].geometry.location,
                            map: map,
                            title: address
                        });

                    } else {
                        alert("No results found");
                    }
                }
            });
        }
    }
    google.maps.event.addDomListener(window, 'load', initialize);


});

HTML

<p id="map">
          Vojvode Dobrnjca, Belgrade
              </p>

<div id="map-canvas"></div>

Upvotes: 0

Views: 65

Answers (1)

Neo
Neo

Reputation: 1469

You had missed center in mapOptions. And you should create geocoder variable in initialize function. Please refer this. I had shown your map.

Upvotes: 1

Related Questions