Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $lat = $_REQUEST['lat'];
- $long = $_REQUEST['long'];
- $radius = (empty($_REQUEST['radius']) ? '500' : $_REQUEST['radius']); //meter
- $zoom = (empty($_REQUEST['zoom']) ? '17' : $_REQUEST['zoom']); // 1 to 22
- $place = (empty($_REQUEST['place']) ? 'hospital' : $_REQUEST['place']); // 1 to 22
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Place Searches</title>
- <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
- <meta charset="utf-8">
- <style>
- /* Always set the map height explicitly to define the size of the div
- * element that contains the map. */
- #map {
- height: 100%;
- }
- /* Optional: Makes the sample page fill the window. */
- html, body {
- height: 100%;
- margin: 0;
- padding: 0;
- }
- </style>
- <script>
- // This example requires the Places library. Include the libraries=places
- // parameter when you first load the API. For example:
- // <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places">
- var map;
- var infowindow;
- function initMap() {
- var pyrmont = {lat: <?php echo $lat ?>, lng: <?php echo $long ?>};
- map = new google.maps.Map(document.getElementById('map'), {
- center: pyrmont,
- zoom: <?php echo $zoom ?>
- });
- infowindow = new google.maps.InfoWindow();
- var service = new google.maps.places.PlacesService(map);
- service.nearbySearch({
- location: pyrmont,
- radius: <?php echo $radius ?>,
- type: ['<?php echo $place ?>']
- }, 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);
- var myloc = place.geometry.location.toString();
- var location = myloc.slice(1, -1);
- var arr = location.split(',');
- var latitute = arr[0];
- var longtitude = arr[1];
- });
- }
- </script>
- </head>
- <body>
- <div id="map"></div>
- <script async defer src="https://maps.googleapis.com/maps/api/js?callback=initMap&libraries=places&fields=photos,formatted_address,name,rating,opening_hours,geometry&key=YOUR_API_KEY"></script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement