Guest User

Untitled

a guest
Feb 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. <input type="text" id="input"/>
  2. <div id="map" style="width: 200px; height: 200px;"></div>
  3.  
  4. $(document).ready(function(){
  5. var map_input = $('#input');
  6. setTimeout(function(){initMap()},'5000');
  7. function initMap() {
  8. var map = new google.maps.Map($('form #map'), {
  9. center: {lat: 33.8892846, lng: 35.539302},
  10. zoom: 11
  11. });
  12.  
  13. var autocomplete = new google.maps.places.Autocomplete(map_input);
  14. var marker = new google.maps.Marker({
  15. map: map
  16. });
  17.  
  18. autocomplete.addListener('place_changed', function() {
  19. var place = autocomplete.getPlace();
  20. if (!place.geometry) {
  21. // User entered the name of a Place that was not suggested and
  22. // pressed the Enter key, or the Place Details request failed.
  23. window.alert("No details available for input: '" + place.name + "'");
  24. return;
  25. }
  26.  
  27. // If the place has a geometry, then present it on a map.
  28. if (place.geometry.viewport) {
  29. map.fitBounds(place.geometry.viewport);
  30. } else {
  31. //map.setCenter(place.geometry.location);
  32. //map.setZoom(17); // Why 17? Because it looks good.
  33. }
  34.  
  35. marker.setPosition(place.geometry.location);
  36. marker.setVisible(true);
  37. });
  38. }
  39. });
Add Comment
Please, Sign In to add comment