Good afternoon, I use api google maps, styled everything as it should, but the question is how to add metro stations to show them and where to see all the available options.

    2 answers 2

    https://developers.google.com/maps/documentation/javascript/examples/layer-transit

    var transitLayer = new google.maps.TransitLayer(); transitLayer.setMap(map); 

      Apply the Places JavaScript of Google Maps APIs library . To use functions from this library, you must first load it using the libraries parameter in the Google Maps API download URL:

       <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places"></script> 

      With this service Places you can perform four types of search:

      • Search for places nearby - returns a list of nearby places depending on the location of the user.
      • Text search - returns a list of nearby places depending on the entered text line, for example: "Metro stations".
      • Mass search - returns a large list of places in the specified search radius, but with a lower level of detail compared to searching for places nearby and text search.
      • Location data requests - return more detailed information about a specific location, including user reviews.

      Finding places nearby

      Finding places nearby allows you to find places in a specified area by keyword or by type. Finding places nearby should always include a location that can be specified in one of the following two ways:

      - LatLngBounds parameter;

      - the area inside the circle defined by the location property, which defines the center of the circle as a LatLng object, and the radius of the circle in meters.

      Example, the nearest metro station:

       <!DOCTYPE html> <html> <head> <title>Ближайшие станции метро</title> <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> <meta charset="utf-8"> <style> #map { height: 100%; } html, body { height: 100%; margin: 0; padding: 0; } </style> <script> var map; var infowindow; function initMap() { var moskva = {lat:55.7479275, lng:37.6393378}; map = new google.maps.Map(document.getElementById('map'), { center: moskva, zoom: 11 }); infowindow = new google.maps.InfoWindow(); var service = new google.maps.places.PlacesService(map); service.nearbySearch({ location: moskva, radius: 10000, type: ['subway_station'] }, callback); } function callback(results, status) { if (status === google.maps.places.PlacesServiceStatus.OK) { for (var i = 0; i < results.length; i++) { createMarker(results[i]); } } } function createMarker(place) { var placeLoc = place.geometry.location; var marker = new google.maps.Marker({ map: map, position: place.geometry.location }); google.maps.event.addListener(marker, 'click', function() { infowindow.setContent(place.name); infowindow.open(map, this); }); } </script> </head> <body> <div id="map"></div> <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places&callback=initMap" async defer></script> </body> </html> 

      To determine the coordinates of the center, you can use this tool iTouchMap . Notice that the type parameter has the contents of a subway_station . See the list of place types .

      Text search

      The Google Places text search service is a web service that returns information about places based on the phrase you entered, for example, Khimki pizzeria or shoe stores near Ivanovo. The service returns a list of places corresponding to the text string of the request and the established preferred location. The answer to the search query will contain a list of places. Required query parameter query is a text string by which the search is performed, for example, "restaurant". The Places service returns the appropriate options based on this string. Results are sorted by relevance. This parameter is optional if the type parameter is also used in the search query. An example for metro stations in Moscow:

       var map; var service; var infowindow; function initialize() { var moskva = new google.maps.LatLng(lat:55.7479275, lng:37.6393378); map = new google.maps.Map(document.getElementById('map'), { center: moskva, zoom: 11 }); var request = { location: moskva, radius: '10000', query: 'subway_station' }; service = new google.maps.places.PlacesService(map); service.textSearch(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]); } } } 

      You can also use KML GeoRSS layers .