Advertisement
jamboljack

GeoCode

Oct 4th, 2018
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.51 KB | None | 0 0
  1. function getAddress() {
  2.     var kecamatan    = $('#lstKec').find(':selected').attr('data-name');
  3.     var kelurahan    = $('#lstDesa').find(':selected').attr('data-name');
  4.     var address      = kelurahan+', '+kecamatan+' KABUPATEN KUDUS JAWA TENGAH';
  5.     console.log(address);
  6.     geocode(address);
  7.     // geocoder.geocode( { 'address': address}, function(results, status) {
  8.     //   if (status == 'OK') {
  9.     //     map.setCenter(results[0].geometry.location);
  10.     //     var marker = new google.maps.Marker({
  11.     //         map: map,
  12.     //         position: results[0].geometry.location
  13.     //     });
  14.     //   } else {
  15.     //     alert('Geocode was not successful for the following reason: ' + status);
  16.     //   }
  17.     // });
  18. }
  19.  
  20. function geocode(address) {
  21.     console.log('geocode');
  22.     $.get('https://maps.googleapis.com/maps/api/geocode/json?address='+encodeURIComponent(address), function(data) {
  23.     if (data.results.length) {
  24.         var lokasi = data.results[0].geometry.location;
  25.         $('#lat').val(lokasi.lng);
  26.         $('#long').val(lokasi.lat);
  27.         $('#map_canvas').locationpicker({
  28.             location: {
  29.                 latitude: lokasi.lat,
  30.                 longitude: lokasi.lng
  31.             },
  32.             radius: 0,
  33.             zoom:15,
  34.             inputBinding: {
  35.                 latitudeInput: $('#lat'),
  36.                 longitudeInput: $('#long')
  37.             },
  38.                 markerInCenter: true,
  39.                 enableAutocomplete: true
  40.             });
  41.         }
  42.     });
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement