Advertisement
Guest User

Java Script nya

a guest
May 26th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  <script type="text/javascript">
  2.         var geocoder;
  3.         var map;
  4.         function initialize() {
  5.             geocoder = new google.maps.Geocoder();
  6.             var latlng = new google.maps.LatLng(-6.9174639, 107.61912280000001);
  7.             var mapOptions = {
  8.                 zoom: 12,
  9.                 center: latlng
  10.             }
  11.             map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
  12.         }
  13.         <?php // membuat fungsi geocoder untuk mendapatkan latitude dan longtitude ?>
  14.         function geocode() {
  15.             var address = document.getElementById('alamat').value;
  16.             geocoder.geocode( { 'address': address}, function(results, status) {
  17.                 if (status == google.maps.GeocoderStatus.OK) {
  18.                     map.setCenter(results[0].geometry.location);
  19.                     var marker = new google.maps.Marker({
  20.                         map: map,
  21.                         position: results[0].geometry.location
  22.                     });
  23.                     var lat = results[0].geometry.location.lat();
  24.                     var lng = results[0].geometry.location.lng();
  25.                 } else {
  26.                     alert('Geocode gagal dilakukan karena : ' + status);
  27.                 }
  28.                 document.getElementById("lat").value = lat;
  29.                 document.getElementById('lng').value=lng;
  30.             });
  31.         }
  32.  
  33.         google.maps.event.addDomListener(window, 'load', initialize);
  34.     </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement