Silahkan Melihat Tutorial di website kami dengan nyaman ENJOY YOUR LIFE ☕

get latitude and longitude from address using google map also seach near by places

HELLO Getting serach near by of your location

get latitude and longitude from address using google map also seach near by places 





<style>
 .textbox {
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    border: 1px solid #848484;
    outline:0;
    height:25px;
    width: 275px;
 }

 .select-style {
    border: 1px solid #ccc;
    width: 120px;
    border-radius: 3px;
    overflow: hidden;
    background: #fafafa url("img/icon-select.png") no-repeat 90% 50%;
}

.select-style select {
    padding: 5px 8px;
    width: 130%;
    border: none;
    box-shadow: none;
    background: transparent;
    background-image: none;
    -webkit-appearance: none;
}

.select-style select:focus {
    outline: none;
}

</style>
<form method="post" action="">
<input type="text" name="placesearch" id="placesearch" class="textbox" placeholder="Plese Enter City" />
<select name="types" class="select-style">
<option value="restaurant">restaurant</option>
<option value="hospital">hospital</option>
<option value="post_office">post_office</option>
<option value="library">library</option>
<option value="cafe">cafe</option>
<option value="bus_station">bus_station</option>
<option value="city_hall">city_hall</option>
<option value="doctor">doctor</option>
<option value="electronics_store">electronics_store</option>
</select>
<input type="submit" value="submit" />
</form>

<?php

// echo  $palcesearch =  isset($_GET['placesearch']);

$palcesearch = isset($_POST['placesearch']) ? $_POST['placesearch'] : "";
$types = isset($_POST['types']) ? $_POST['types'] : "";


 //echo $_GET['placesearch'];
//Set up our variables
$longitude = "";
$latitude = "";
$precision = "";

//Three parts to the querystring: q is address, output is the format (
$key = "JusT Add Your Api Key";
$address = urlencode($palcesearch);

if(!empty($address)){

//echo $address;
//$url = "https://maps.googleapis.com/maps/api/geocode/json?address=".$address."&amp;output=csv&amp;key=".$key;

$url = "https://maps.googleapis.com/maps/api/geocode/json?address=".$address."&key=".$key."";


$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);

// Will dump a beauty json :3
$data = (json_decode($result, true));

//echo "<pre>";
//print_r($data);

 echo $lat = $data['results'][0]['geometry']['location']['lat'];
  echo $lng =  $data['results'][0]['geometry']['location']['lng'];
}
else{
 
    echo "Plase Enter Your Address";
}
/*$ahemadabad_lan = "37.4217550";
$ahemadabad_lat = "-122.0846330";*/
?>

<!DOCTYPE html>
<html>
  <head>
    <title>Place searches</title>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <style>
      html, body, #map-canvas {
        height: 90%;
        margin: 0px;
        padding: 0px;
        top:20px;
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script>
    <script>
var map;
var infowindow;

function initialize() {
  var pyrmont = new google.maps.LatLng(<?php echo $lat; ?>,<?php echo $lng; ?> );


  map = new google.maps.Map(document.getElementById('map-canvas'), {
    center: pyrmont,
    zoom: 12
  });

  var request = {
    location: pyrmont,
    radius: 500000,
    types: ['<?php echo $types; ?>']
  };
  infowindow = new google.maps.InfoWindow();
  var 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++) {
      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);
  });
}

google.maps.event.addDomListener(window, 'load', initialize);

    </script>
  </head>
  <body>
    <div id="map-canvas"></div>
  </body>
</html>




0 komentar:

Post a Comment

get latitude and longitude from address using google map also seach near by places