Domanda

          function initialize() {
            var geocoder =  new google.maps.Geocoder();
            geocoder.geocode( { 'address': '111 8th Avenue, New York, NY'}, function(results, status) {
              if (status == google.maps.GeocoderStatus.OK) {
                var point =  new google.maps.LatLng( results[0].geometry.location.lat() + ", " +results[0].geometry.location.lng() );
                //alert( results[0].geometry.location.lat() + ", " +results[0].geometry.location.lng() );
                //var point = new google.maps.LatLng(40.7406578, -74.00208940000005);
                setTimeout(function(){
                  var mapOptions = {
                    zoom: 11,
                    center: point
                  };
                  var map = new google.maps.Map(document.getElementById('map-canvas'),
                      mapOptions);    
                  var marker = new google.maps.Marker({
                      position: point,
                      map: map,
                      title: "111 8th Avenue, New York, NY"
                  }); 
                }, 1000);
              }
            });
          }      
          google.maps.event.addDomListener(window, 'load', initialize);

I am trying to view google map by adding 'address'. I get the lat & long, but nothing shows. It works if I add manually the lat & long..

var point = new google.maps.LatLng(40.7406578, -74.00208940000005);
È stato utile?

Soluzione

The line (you are making a string inside)

var point =  new google.maps.LatLng( results[0].geometry.location.lat() + ", " +results[0].geometry.location.lng() );

has to be:

var point =  new google.maps.LatLng( results[0].geometry.location.lat(),  results[0].geometry.location.lng() );
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top