Advertisement
darighteous1

address autocomplete

Nov 5th, 2015
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $city = 'Alpharetta';
  4. $region = 'GA (Georgia)';
  5. $zipcode = '30022';
  6.  
  7. $city2 = 'Stony Point';
  8. $region2 = 'NY (New York)';
  9. $zipcode2 = '10980';
  10. ?>
  11. <!DOCTYPE html>
  12. <html>
  13.   <head>
  14.     <title>Simple Map</title>
  15.     <meta name="viewport" content="initial-scale=1.0, user-scalable = no">
  16.     <meta charset="utf-8">
  17.     <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDcy8ewVLI6L_YrdhgmpTP7T-yDekbcCek&signed_in=true&libraries=places&callback=initAutocomplete" async defer></script>
  18.   </head>
  19.   <body>
  20.     <div class="itinerary_fields">
  21.         <p><label>Exact Address:</label>  <span class="locationField"><input style="width: 500px;" class="address_autocomplete" id="autocomplete" placeholder="Enter your address"
  22.              onFocus="geolocate(<?=$zipcode?>);" type="text"></input></span>, <span class="address"><?=$city?>, <?=$region?>, <?=$zipcode?></span></p>
  23.         <p><label class="textfield">Notes:</label><textarea placeholder="Optional Location Description"></textarea></p>
  24.  
  25.         <!-- <p><label>Exact Address:</label>  <span id="locationField"><input style="width: 500px;" class="address_autocomplete" placeholder="Enter your address"
  26.              onFocus="geolocate(<?=$zipcode2?>);" type="text"></input></span>, <span class="address"><?=$city2?>, <?=$region2?>, <?=$zipcode2?></span></p>
  27.         <p><label class="textfield">Notes:</label><textarea placeholder="Optional Location Description"></textarea></p> -->
  28.     </div>
  29.  
  30.      <script>
  31.  
  32.         var autocomplete;
  33.  
  34.         function initAutocomplete() {
  35.           // Create the autocomplete object, restricting the search to geographical
  36.           // location types.     
  37.            
  38.             autocomplete = new google.maps.places.Autocomplete(
  39.               /** @type {!HTMLInputElement} */(document.getElementById('autocomplete')),
  40.               {
  41.                 types: ['geocode'],
  42.                 componentRestrictions: {
  43.                     country: 'us'
  44.                 }
  45.               });
  46.         }
  47.  
  48.         // [START region_geolocation]
  49.         // Bias the autocomplete object to the user's geographical location,
  50.         // as supplied by the browser's 'navigator.geolocation' object.
  51.         function geolocate(zipcode) {
  52.             var geocoder = new google.maps.Geocoder;
  53.  
  54.             geocoder.geocode({
  55.                 'address': String(zipcode)
  56.             }, function (results, status) {
  57.                 if (status == google.maps.GeocoderStatus.OK) {
  58.                    
  59.                     var circle = new google.maps.Circle({
  60.                         center: results[0].geometry.location,
  61.                         radius: 50000 //in meters
  62.                     });
  63.  
  64.                     autocomplete.setBounds(circle.getBounds());
  65.                 }
  66.             });
  67.         }
  68.         // [END region_geolocation]
  69.  
  70.     </script>
  71. </body>
  72. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement