ssmsnet
ssmsnet

Reputation: 2306

Google Map V3.0 Places Api

I am working on a GoogleMap Project. I am struck on a task from 3 days(long days really).. Unable to finish the task. I am a begineer to JavaScript.

I want to achieve something as shown in the Link for a UK Location. I have changed it to the Uk Location(LONDON) and changed the types to bank. Basically I was expecting the banks pin in the given radius to display. But it is not doing that. I changes the types to train_station, strangley i am getting wrongoutput.

The Code I am using is as shown Below. can anyone Help me please..

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html> 
<head> 
  <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
  <title>Google Maps JavaScript API v3 Example: Place Search</title> 

  <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=places"></script> 

  <style type="text/css">
    #map {
      height:500px;
      width:100%;

    }
  </style>

  <script type="text/javascript">

      var map;
      var service;
      var infowindow;

      function initialize() {

      // Australia PostCode
         //var pyrmont = new google.maps.LatLng(-33.8665433, 151.1956316);
          // Uk Post Code
          //Northampton
          //var pyrmont = new google.maps.LatLng(52.238, -0.895);
          //London
          var pyrmont = new google.maps.LatLng(51.4916807, -0.1920284);

        //  var pyrmont = new google.maps.LatLng(40.704, -70.0083);


          map = new google.maps.Map(document.getElementById('map'), {
              mapTypeId: google.maps.MapTypeId.ROADMAP,
              center: pyrmont,
              zoom: 12
          });
          var request = {
              location: pyrmont,
              radius: '50000',
              types: ['train_station']

          };
          infowindow = new google.maps.InfoWindow();
          service = new google.maps.places.PlacesService(map);
          service.search(request, callback);
      }

      function callback(results, status) {
          if (status == google.maps.places.PlacesServiceStatus.OK) {
              for (var i = 0; i < results.length; i++) {
                  var place = results[i];
                  createMarker(results[i]);
              }
          }
      }

      function createMarker(place) {

          var placeLoc = place.geometry.location;
          var marker = new google.maps.Marker({
              map: map,

              position: new google.maps.LatLng(placeLoc.lat(), placeLoc.lng())
          });
          google.maps.event.addListener(marker, 'click', function () {
              infowindow.setContent(place.name);
              infowindow.open(map, this);
          });
      }

  </script> 
</head> 
<body onload="initialize()"> 
  <div id="map"></div>
  <div id="text">
    <pre>
var request = {
  bounds: new google.maps.LatLngBounds(
      new google.maps.LatLng(-33.867114, 151.1957),
      new google.maps.LatLng(-33.866755, 151.196138)),
  types: ['political']
};
    </pre>
    </div>
</body> 
</html> 

Upvotes: 0

Views: 4575

Answers (2)

sarah.w.99
sarah.w.99

Reputation: 19

In the meantime, searching for name=bank or name=train+station (instead of using types) will probably give you what you're looking for.

Upvotes: 0

Trott
Trott

Reputation: 70065

Google Places does not appear to have very much in London at the current time. When you omit the types array altogether, it only returns a handful of places. None of them appear to be train stations or banks. So you will have to add the train stations and banks to Google Places first.

Despite the lack of data currently in Google Places for London, the API is working. You can see a bunch of results if you use 'museum' as the element in your types array, for example.

No idea what's up with that 'train_station' wrong output issue, though. The Google Places API is experimental. Perhaps you should file a bug with Google. The issue tracker is at http://code.google.com/p/gmaps-api-issues/issues/list. Select "Places API - Bug" from the first pull down item when filing the bug.

Upvotes: 2

Related Questions