Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Commit

Permalink
autoinit: coordinate field (google maps)
Browse files Browse the repository at this point in the history
  • Loading branch information
uyab committed Sep 26, 2019
1 parent e72ed59 commit c9c7874
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion public/js/all.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"/css/app.css": "/css/app.css?id=9ccf21a457016100da27",
"/js/all.js": "/js/all.js?id=583560685927de9e3b48",
"/js/all.js": "/js/all.js?id=cba58a134834ca40beee",
"/css/all.css": "/css/all.css?id=7b2e7f4696f2d3bf19b0",
"/semantic/semantic.min.css": "/semantic/semantic.min.css?id=395cd6af3c3778570b67"
}
41 changes: 41 additions & 0 deletions resources/js/init/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,47 @@ $(function () {
});
});
}


if (typeof google === 'object' && typeof google.maps === 'object') {
$('[data-form-coordinate]').each(function () {
var input = $(this);
var long, lat;
[lat, long] = input.val().split(',');
lat = lat || -7.451808;
long = long || 111.035929;

var mapContainer = $('<div>')
.css('width', '100%')
.css('height', 300)
.css('border-radius', 4)
.css('margin-top', '5px');

mapContainer.insertAfter($(this));

var center = new google.maps.LatLng(lat, long);
var options = {
zoom: 17,
center: center,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(mapContainer[0], options);

var marker = new google.maps.Marker({
position: center,
map: map,
draggable: true
});
google.maps.event.addListener(
marker,
'drag',
function () {
input.val(marker.position.lat() + ',' + marker.position.lng());
}
);
});
}

});


0 comments on commit c9c7874

Please sign in to comment.