| Current Path : /home/users/unlimited/www/foodbank.codeskitter.site/public/frontend/js/ |
| Current File : /home/users/unlimited/www/foodbank.codeskitter.site/public/frontend/js/map-current.js |
/**
*
* You can write your JS code here, DO NOT touch the default style file
* because it will make it harder for you to update.
*
*/
"use strict";
var mapLat = mapLat;
var mapLong = mapLong;
function initAutocomplete() {
if (mapLat != '' && mapLong != '') {
getLocation(mapLat, mapLong);
} else {
getLocation(null, null);
}
var input = document.getElementById('autocomplete-input');
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.addListener('place_changed', function () {
var place = autocomplete.getPlace();
$('#lat').val(place.geometry.location.lat());
$('#long').val(place.geometry.location.lng());
if (!place.geometry) {
return;
}
});
if ($('.main-search-input-item')[0]) {
setTimeout(function () {
$(".pac-container").prependTo("#autocomplete-container");
}, 300);
}
}
var geocoder;
function getLocation(lat, long) {
geocoder = new google.maps.Geocoder();
if (navigator.geolocation) {
if (lat && long) {
showGetPosition(lat, long)
} else {
navigator.geolocation.getCurrentPosition(showPosition);
}
} else {
var msg = "Geolocation is not supported by this browser.";
alert(msg);
}
}
function showPosition(position) {
var Latitude = position.coords.latitude;
var Longitude = position.coords.longitude;
$('#lat').val(Latitude);
$('#long').val(Longitude);
var latlng = new google.maps.LatLng(Latitude, Longitude);
geocoder.geocode({
'latLng': latlng
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
$('#autocomplete-input').val(results[0].formatted_address);
}
}
})
}
function showGetPosition(lat, long) {
var Latitude = lat;
var Longitude = long;
$('#lat').val(Latitude);
$('#long').val(Longitude);
var latlng = new google.maps.LatLng(Latitude, Longitude);
geocoder.geocode({
'latLng': latlng
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
$('#autocomplete-input').val(results[0].formatted_address);
}
}
})
}