Google places javascript library to search for places inside my database

StackOverflow https://stackoverflow.com/questions/15599309

  •  29-03-2022
  •  | 
  •  

Вопрос

I have a mysql database with places.Each place has a longitude/latitude. What I want is to search for places inside an area, e.g. places inside London. Is this possible to do with the Google places javascript library? thanks!

Это было полезно?

Решение

All of this and more is possible using the Google Places JavaScript library.

There's a code snippet on the page above that does exactly that (searching for places based on longitude / latitude).

var map;
var service;
var infowindow;

function initialize() {
  var pyrmont = new google.maps.LatLng(-33.8665433,151.1956316);

  map = new google.maps.Map(document.getElementById('map'), {
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: pyrmont,
      zoom: 15
    });

  var request = {
    location: pyrmont,
    radius: '500',
    types: ['store']
  };

  service = new google.maps.places.PlacesService(map);
  service.nearbySearch(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]);
    }
  }
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top