   
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDdCZSgU2mNRDoTY9Vczvqp0Jjkqm3TWKQ&libraries=places,geocoder"></script>
    <script>

        function initialize() {
          var geocoder = new google.maps.Geocoder();
          var myLatLng = {lat: 1.3544537553607754, lng: 103.86753559112549};
          var mapOptions = {
            center: myLatLng,
            zoom: 15,
            scrollwheel: false
          };
          var map = new google.maps.Map(document.getElementById('map'),
            mapOptions);

          var input = /** @type {HTMLInputElement} */(
              document.getElementById('pac-input'));

          // Create the autocomplete helper, and associate it with
          // an HTML text input box.
          var autocomplete = new google.maps.places.Autocomplete(input);
          autocomplete.bindTo('bounds', map);

          var infowindow = new google.maps.InfoWindow();
          var marker = new google.maps.Marker({
            map: map,
            draggable:true,
          });

          function placeMarker(location) {
              if ( marker ) {
                  marker.setPosition(location);
                  //change coordinates when you drag the marker
                  google.maps.event.addListener(marker, 'dragend', function(event){
                      var pos = event.latLng;
                      var latitude = pos.lat();
                      var longitude = pos.lng();
                      var lat = latitude.toFixed(6);
                      var lng = longitude.toFixed(6);
                      document.getElementById('coordinates').value = latitude + ',' + longitude;

                      geocoder.geocode({'location': pos}, function(results, status) {
                      if (status === google.maps.GeocoderStatus.OK) {
                        if (results[1]) {
                          placeMarker(event.latLng);

                          infowindow.setContent(results[0].formatted_address + "<br>" + "Latitude: " + lat + " | " + "Longitude: " + lng);
                          infowindow.open(map, marker);

                        } else {
                          window.alert('No results found');
                        }
                      }

                      });
                  });
              }
            }

          // Get the full place details when the user selects a place from the
          // list of suggestions.
          google.maps.event.addListener(autocomplete, 'place_changed', function(event) {
            infowindow.close();

            var place = autocomplete.getPlace();
            if (!place.geometry) {
              return;
            }

            if (place.geometry.viewport) {
              map.fitBounds(place.geometry.viewport);
            } else {
              map.setCenter(place.geometry.location);
              map.setZoom(17);
            }

            // Set the position of the marker using the place ID and location.
            placeMarker(place.geometry.location);
            var latitude = place.geometry.location.lat();
            var longitude = place.geometry.location.lng();
            document.getElementById('coordinates').value = latitude.toFixed(6) + ', ' + longitude.toFixed(6);
            var coordinates =  latitude + ', ' + longitude;
            ddToDms(coordinates);

                geocoder.geocode({'location': place.geometry.location}, function(results, status) {
                if (status === google.maps.GeocoderStatus.OK) {
                  if (results[1]) {
                    placeMarker(place.geometry.location);

                    infowindow.setContent(results[0].formatted_address + "<br>" + "Latitude: " + place.geometry.location.lat() + " | " + "Longitude: " + place.geometry.location.lng());
                    infowindow.open(map, marker);

                  } else {
                    window.alert('No results found');
                  }
                }

                });
          });

          //location info after click the map
            google.maps.event.addListener(map, 'click', function(event) {
              var pos = event.latLng;
              var latitude = pos.lat();
              var longitude = pos.lng();
              var lat = latitude.toFixed(6);
              var lng = longitude.toFixed(6);


              document.getElementById('coordinates').value = latitude.toFixed(6) + ', ' + longitude.toFixed(6);
              var coordinates = latitude.toFixed(6) + ', ' + longitude.toFixed(6);

              ddToDms(coordinates);

                geocoder.geocode({'location': pos}, function(results, status) {
                if (status === google.maps.GeocoderStatus.OK) {
                  if (results[1]) {
                    placeMarker(event.latLng);

                    infowindow.setContent(results[0].formatted_address + "<br>" + "Latitude: " + lat + " | " + "Longitude: " + lng);
                    infowindow.open(map, marker);

                  } else {
                    window.alert('No results found');
                  }
                }

                });

            });
        }

        setTimeout(function(){
            $('#message-s').addClass('hide');
        },2000);
        $('.pac-input').keypress(function(e){
                if ( e.which == 13 ) return false;
                //or...
                alert('fdf');
                if ( e.which == 13 ) e.preventDefault();
            });

        $(document).on('change','select.ajaxEvent',function() {
            var token = $('input[name=_token]').val();
            var model = $(this).data('model');
            var value = $(this).val();

              if(value == "")
                  value=0;

                    $.ajax({
                      headers: {'X-CSRF-TOKEN': token},
                      type: 'GET',
                      datatype: 'json',
                      url: '{{ url("") }}/ajax/' + model + '/'+ value + '/fetch',
                      success: function(data){

                            var obj = data;
                            var div_id = obj.div;
                            var div_element ="#" + div_id + "";
                            $(div_element).html(obj.result);
                      }
                    });

          });

        $(function(){

            $('#deployment_date').datetimepicker({
                format: 'DD-MM-YYYY'
            });


        });


        // This function returns the coordinate
        // conversion string in DD to DMS.
        function ddToDms(coordinates) 
        {
          
           var coords = coordinates.split(',');
           var lat = coords[0];
           var lng = coords[1];
           var latResult, lngResult, dmsResult;


           if(lat != "" && lng != "" && !isNaN(parseFloat(lat)) && !isNaN(parseFloat(lng)))
           {
             lat = parseFloat(lat);  
             lng = parseFloat(lng);

           
             // Call to getDms(lat) function for the coordinates of Latitude in DMS.
             // The result is stored in latResult variable.
             latResult = getDms(lat);

             latResult += (lat >= 0)? ' N' : ' S';


          

             // Call to getDms(lng) function for the coordinates of Longitude in DMS.
             // The result is stored in lngResult variable.
             lngResult = getDms(lng);
             lngResult += (lng >= 0)? ' E' : ' W';

             // Joining both variables and separate them with a space.
             dmsResult = latResult + ', ' + lngResult;

             $('#coordinates_dms').val(dmsResult);

             // Return the resultant string
             return dmsResult;
           }
           else
           {
              $('#coordinates_dms').val("");
              return "";
           }
        }

        function getDms(val) 
        {

          var valDeg, valMin, valSec, result;

          val = Math.abs(val);

          valDeg = Math.floor(val);
          result = valDeg + "";

          valMin = Math.floor((val - valDeg) * 60);
          result += valMin + "'";

          valSec = Math.round((val - valDeg - valMin / 60) * 3600 * 1000) / 1000;
          result += valSec + '"';

          return result;
        }



        //DMS To DECIMAL

        function ParseDMS(input) 
        {
          if(input != "")
          {
            var parts = input.split(/[^\d\w\.]+/);    
            var lat = ConvertDMSToDD(parts[0], parts[1], parts[2], parts[3]);
            var lng = ConvertDMSToDD(parts[4], parts[5], parts[6], parts[7]);

            var coordinates =   lat.toFixed(6) + ', ' + lng.toFixed(6);
            $('#coordinates').val(coordinates);


            return {
                Latitude : lat,
                Longitude: lng,
                Position : coordinates
            }
          }
          else
          {
            $('#coordinates').val("");
            return "";
          }
        }


        function ConvertDMSToDD(degrees, minutes, seconds, direction) 
        {   
            var dd = Number(degrees) + Number(minutes)/60 + Number(seconds)/(60*60);

            if (direction == "S" || direction == "W") 
            {
                dd = dd * -1;
            } 
            // Don't do anything for N or E
            return dd;
        }




        $(document).ready(function(){

            $('#coordinates').on('change',function(){

                  var dms = ddToDms($(this).val());
                 
                  
               
            });

            $('#coordinates_dms').on('change',function(){

                  var coordinates = ParseDMS($(this).val());
                 
                  
               
            });


            google.maps.event.addDomListener(window, 'load', initialize);
            $('#pac-input').keypress(function(e){
                if ( e.which == 13 ) e.preventDefault();
            });
        })
    </script>
