title: How to get a geo location and show to the map
body: <p>I have been trying to get a location address from a text box then get the latitude and longitude from the address and show the nearest train station from the address.</p>
  
  <p>I can get the latitude and longitude of an address
  I also can show the nearest train stations from a specific latitude and longitude.</p>
  
  <p>My problem is when I try to get the latitude and longitude form an address and put the address latitude and longitude to show the nearest train station, I failed.</p>
  
  <p>Please find my code below(problem is in alert-)-</p>
  
  <pre><code>function initialize() {
  
          // start
          var latitude;
          var longitude;
          geocoder = new google.maps.Geocoder();
          var address = document.getElementById('address').value;
          geocoder.geocode({ 'address': address }, function (results, status) {
              if (status == google.maps.GeocoderStatus.OK) {
                  map.setCenter(results[0].geometry.location);
                  var marker = new google.maps.Marker({
                      map: map,
                      position: results[0].geometry.location
                  });
                  latitude = results[0].geometry.location.lat();
                  longitude = results[0].geometry.location.lng();
                  alert(longitude);
  
              } else {
                  alert('Geocode was not successful for the following reason: ' + status);
              }
          });
  
          alert(longitude);
  
          var pyrmont = new google.maps.LatLng(-37.8176108, 145.0422631);
  
          map = new google.maps.Map(document.getElementById('map-canvas'), {
              center: pyrmont,
              zoom: 15
          });
  
          var request = {
              location: pyrmont,
              radius: 1000,
              types: ['train_station', 'bus_station', 'subway_station',   'transit_station']
          };
          infowindow = new google.maps.InfoWindow();
          var service = new google.maps.places.PlacesService(map);
          service.nearbySearch(request, callback);  
  
      }
  </code></pre>