// Set url service app var urlRequest = "http://locmap.at/admin/"; var urlService = urlRequest+"index.php/"; var newUrlRequest = "http://locmap.at/engine/ajax/ajax.php/"; // Set maps variabel var map, myLat, myLong, myRadius, userLocation, address, panorama, streetPlace; var geocoder = new google.maps.Geocoder(); var infowindow = new google.maps.InfoWindow(); var bounds = new google.maps.LatLngBounds(); var directionsService = new google.maps.DirectionsService(); var directionsDisplay = new google.maps.DirectionsRenderer(); var markers = []; // Get detection user location function myGeoloc(){ if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(myGeolocSuccess, myGeolocError,{enableHighAccuracy:true}); } else { error('Geolocation not supported'); } } myGeoloc(); // Get user location function myGeolocSuccess(position) { myLat = position.coords.latitude; myLong = position.coords.longitude; myRadius = position.coords.accuracy; userLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude); geocoder.geocode( { 'latLng': userLocation}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { address = results[0].formatted_address; } var pw = $(window).width(); //Generate location images $("#page_home .slider ul").empty(); $("#page_home .slider ul").append('
  • '); $("#page_home .slider ul").append('
  • '); }); // Set marker location user var marker = new google.maps.Marker({ map: map, icon: "img/pin/pin2.png", position: userLocation, animation: google.maps.Animation.DROP, title: location.nama }); // Set accuracy location user var circle = new google.maps.Circle({ center: userLocation, radius: position.coords.accuracy, map: map, fillColor: '#FF3300', fillOpacity: 0.2, strokeColor: '#FF3300', strokeOpacity: 0.4 }); //map.fitBounds(circle.getBounds()); markers.push(marker); } // Get user location not found function myGeolocError() { log('Location Not Found!'); } // Set maps properties function init(req,status,street) { if(!req){ var req = ''; } var mapOptions = { mapTypeId: google.maps.MapTypeId.ROADMAP } // Set id to display maps map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); // Request result directions maps if(status == 1){ directionsDisplay.setMap(map); directionsDisplay.setPanel(document.getElementById('directions-route')); }else{ directionsDisplay.setMap(null); $('#directions_panel').empty(); } if($('#toggle-traffic-layer').prop('checked')){ // Display traffic layer maps var trafficLayer = new google.maps.TrafficLayer(); trafficLayer.setMap(map); } if($('#toggle-weather-layer').prop('checked')){ // Display weather layer maps var weatherLayer = new google.maps.weather.WeatherLayer({temperatureUnits: google.maps.weather.TemperatureUnit.celsius}); weatherLayer.setMap(map); } if($('#toggle-panoramio-layer').prop('checked')){ // Display panoramio layer maps var panoramioLayer = new google.maps.panoramio.PanoramioLayer(); panoramioLayer.setMap(map); } if($('#toggle-transit-layer').prop('checked')){ // Display transit layer maps var transitLayer = new google.maps.TransitLayer(); transitLayer.setMap(map); } if($('#toggle-bike-layer').prop('checked')){ // Display bike layer maps var bikeLayer = new google.maps.BicyclingLayer(); bikeLayer.setMap(map); } // We get the map's default panorama and set up some defaults. // Note that we don't yet set it visible. panorama = map.getStreetView(); panorama.setPosition(streetPlace); panorama.setPov(({ heading: 265, pitch: 0 })); if (street == "true") { panorama.setVisible(true); } else { panorama.setVisible(false); } // Set url requst maps data var url = urlService+'service/get_maps?clear='+req; // Get request data getRequest(url, function(data) { var data = JSON.parse(data.responseText); for (var i = 0; i < data.length; i++) { var loc; loc = data[i]; var d = new Date(); var month = parseInt(d.getMonth())+1; var date = d.getDate()+"-"+month+"-"+d.getFullYear(); url = newUrlRequest+"?act=timeDetailListMyLocation&id="+loc.markers_id+"&date="+date; getRequest(url, function(datatime){ var datatime = JSON.parse(datatime.responseText); if(datatime.answer == 1){ var d = new Date(); var this_time = datatime.time; var this_time_first = String(this_time.split('-')[0]); var this_time_last = String(this_time.split('-')[1]); var this_time_first_hour = this_time_first.split(':')[0]; var this_time_first_min = this_time_first.split(':')[1]; var this_time_last_hour = this_time_last.split(':')[0]; var this_time_last_min = this_time_last.split(':')[1]; var this_time = parseInt(d.getHours())*60+parseInt(d.getMinutes()); var this_time_first = parseInt(this_time_first_hour)*60+parseInt(this_time_first_min); var this_time_last = parseInt(this_time_last_hour)*60+parseInt(this_time_last_min); if(this_time_first < this_time && this_time < this_time_last){ var act = 2; } else { var act = 1; } } else { var act = 1; } displayLocation(act, loc); }); } if(!req){ map.fitBounds(bounds); map.panToBounds(bounds); } }); } // Display maps markers function displayLocation(act, location) { if(act == 2){ var icon_marker = urlRequest+'upload/logo/'+location.markers_logo_on; } else { var icon_marker = urlRequest+'upload/logo/'+location.markers_logo_off; } if(!$('#toggle-offline-layer').prop('checked') && act != 2){ alert('dont show'); } else { alert('show'); } var content = '
    ' + location.markers_name + '' + '
    ' + location.category_name + '
    ' + location.markers_address + '
    '; if (parseInt(location.markers_lat) == 0) { geocoder.geocode( { 'address': location.markers_address }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var marker = new google.maps.Marker({ map: map, icon: icon_marker, position: results[0].geometry.location, title: location.markers_name }); bounds.extend(marker.position); google.maps.event.addListener(marker, 'click', function() { infowindow.setContent(content); infowindow.open(map,marker); }); markers.push(marker); } }); } else { var position = new google.maps.LatLng(parseFloat(location.markers_lat), parseFloat(location.markers_lng)); var marker = new google.maps.Marker({ map: map, icon: icon_marker, position: position, title: location.markers_name }); bounds.extend(marker.position); google.maps.event.addListener(marker, 'click', function() { infowindow.setContent(content); infowindow.open(map,marker); }); markers.push(marker); } } // Get calculate route maps function calculateRoute(lng,lat) { var destination = new google.maps.LatLng(lat,lng); var request = { origin: userLocation, destination: destination, travelMode: google.maps.DirectionsTravelMode.DRIVING }; directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); } }); } function getRequest(url, callback) { $('.loading').show(); var request; if (window.XMLHttpRequest) { request = new XMLHttpRequest(); // IE7+, Firefox, Chrome, Opera, Safari } else { request = new ActiveXObject("Microsoft.XMLHTTP"); // IE6, IE5 } request.onreadystatechange = function() { if (request.readyState == 4 && request.status == 200) { callback(request); $('.loading').hide(); } } request.open("GET", url, true); request.send(); } function getCalculateRoute(lng,lat){ window.location.href = "#page_location_map"; setTimeout('init("false","1")',2500); calculateRoute(lng,lat) } function getLocationRoute(lng,lat){ window.location.href = "#page_location_route"; init("false","1"); setTimeout('init("false","1")',2500); calculateRoute(lng,lat) } function getLocationCategory(){ $('#list-category').empty(); var url = urlService+'service/get_category'; getRequest(url, function(data) { var data = JSON.parse(data.responseText); for (var i = 0; i < data.length; i++) { $('#list-category').append("
  • "+data[i]['category_name']+""+data[i]['count']+"
  • "); } }); } // Get geolocation list function getLocationList(categoryId){ $('#search-list').val(''); $('#list-detail').empty(); $('#category-id').val(categoryId); var url = urlService+'service/get_list?id='+categoryId; getRequest(url, function(data) { var data = JSON.parse(data.responseText); for (var i = 0; i < data.length; i++) { $('#list-detail').append("
  • "+data[i]['markers_name']+"

    "+data[i]['markers_address']+"

  • "); var d = new Date(); var month = parseInt(d.getMonth())+1; var date = d.getDate()+"-"+month+"-"+d.getFullYear(); url = newUrlRequest+"?act=timeDetailListMyLocation&id="+data[i]['markers_id']+"&date="+date; getRequest(url, function(datatime){ var datatime = JSON.parse(datatime.responseText); if(datatime.answer == 1){ var d = new Date(); var this_time = datatime.time; var this_time_first = String(this_time.split('-')[0]); var this_time_last = String(this_time.split('-')[1]); var this_time_first_hour = this_time_first.split(':')[0]; var this_time_first_min = this_time_first.split(':')[1]; var this_time_last_hour = this_time_last.split(':')[0]; var this_time_last_min = this_time_last.split(':')[1]; var this_time = parseInt(d.getHours())*60+parseInt(d.getMinutes()); var this_time_first = parseInt(this_time_first_hour)*60+parseInt(this_time_first_min); var this_time_last = parseInt(this_time_last_hour)*60+parseInt(this_time_last_min); if(this_time_first < this_time && this_time < this_time_last){ var active = ''; } else { var active = ''; } } else { var time_line = 0; var active = ''; } $("#active-"+datatime.marker_id).html(active); }); } }); } // Get filter list function getFilterList(categoryId){ var categoryId = $('#category-id').val(); var filter = $('#search-list').val(); var url = urlService+'service/get_list?id='+categoryId+"&q="+filter; getRequest(url, function(data) { var data = JSON.parse(data.responseText); $('#list-detail').empty(); for (var i = 0; i < data.length; i++) { $('#list-detail').append("
  • "+data[i]['markers_name']+"

    "+data[i]['markers_address']+"

  • "); } }); } // Get nearby location function getNearby(){ if($('#toggle-nearby-distances').prop('checked')){ var distances = "km"; }else{ var distances = "mil"; } var url = urlService+'service/get_nearby?lat='+myLat+"&long="+myLong+"&option="+distances; getRequest(url, function(data) { var data = JSON.parse(data.responseText); $('#list-nearby').empty(); $('#list-nearby').append("
  • Near "+address+"
  • "); for (var i = 0; i < data.length; i++) { var logo = urlRequest+"/upload/logo/"+data[i]['markers_logo']; $('#list-nearby').append("
  • "+data[i]['markers_name']+"

    "+data[i]['markers_address']+"

    "+data[i]['distance']+" "+ distances +"
  • "); } }); } var now = Math.round(new Date().getTime() / 1000); // Get timestamp var selected_index = -1; //Index of the selected list item var tbSaveLocation = localStorage.getItem("tbSaveLocation");//Retrieve the stored data tbSaveLocation = JSON.parse(tbSaveLocation); //Converts string to object if(tbSaveLocation == null) //If there is no data, initialize an empty array tbSaveLocation = []; function addMyLocation(){ var url = newUrlRequest+"?act=addMyLocation&paren_id="+$("#form-parent-id").val()+"&title="+$("#form-title").val()+"&description="+$("#form-desc").val()+"&lng="+myLong+"&lat="+myLat+"&location="+address+"&date="+now; getRequest(url, function(data){}); } function listMyLocation(){ $('#list-save-location').empty(); $('.loading').hide(); $('#show-location-address').html("Near : "+address); var url = newUrlRequest+"?act=listMyLocation"; getRequest(url, function(data){ var data = JSON.parse(data.responseText); for(var i in data.id){ var date = new Date(data.date[i] * 1000); $('#list-save-location').append("
  • "+data.title[i]+"

    "+date.toLocaleString()+"

  • ");//Delete } }); } function detailListMyLocation(selected_index){ var url = newUrlRequest+"?act=detailListMyLocation&id="+selected_index; getRequest(url, function(data){ var data = JSON.parse(data.responseText); window.location.href = "#page_detail_save_location"; var date = new Date(data.date * 1000); var pw = $(window).width(); $("#page_detail_save_location .slider ul").empty(); $("#page_detail_save_location .slider ul").append('
  • '); $("#page_detail_save_location .slider ul").append('
  • '); $("#date-save-location").html(date); $("#title-save-location").html(data.title); $("#address-save-location").html(data.location); $("#desc-save-location").html(data.description); $("#button-save-location").html('Map View'); $("#num_like_this_detail_save_location").html(data.numlike); $("#num_dislike_this_detail_save_location").html(data.numdislike); $("#like_this_detail_save_location").attr("onClick", "like_this("+data.id+", 'like', 'location_like');"); $("#dislike_this_detail_save_location").attr("onClick", "like_this("+data.id+", 'dislike', 'location_like');"); }); } function like_this(paren_id, type_like, type_parent){ var url = newUrlRequest+"?act=detailListMyLocationLike&paren_id="+paren_id+"&type_like="+type_like+"&type_parent="+type_parent; getRequest(url, function(data){ var data = JSON.parse(data.responseText); if(data.answer == 1){ $("#num_like_this_detail_save_location").html(data.numlike); $("#num_dislike_this_detail_save_location").html(data.numdislike); } }); } function detailShowLocation(id){ $('#show-images').empty(); var url = urlService+'service/get_detail?id='+id; getRequest(url, function(data) { var data = JSON.parse(data.responseText); for (var i = 0; i < data.length; i++) { var urlGetImages = urlRequest+'service/get_images?id='+data[i]['markers_id']; getRequest(urlGetImages, function(dataImages) { var dataImages = JSON.parse(dataImages.responseText); for (var i = 0; i < dataImages.length; i++) { $('#show-images').append('
  • '); } }); $('#btn-show-map').attr('onClick','getShowLocation('+data[i]['markers_lng']+','+data[i]['markers_lat']+',"'+data[i]['category_marker']+'")'); $('#btn-show-street').attr('onClick','getStreetView('+data[i]['markers_lng']+','+data[i]['markers_lat']+')'); $('#btn-show-directions').attr('onClick','getCalculateRoute('+data[i]['markers_lng']+','+data[i]['markers_lat']+')'); $('#btn-show-route').attr('onClick','getLocationRoute('+data[i]['markers_lng']+','+data[i]['markers_lat']+')'); $("#title-show-category").html(data[i]['category_name']); $("#title-show-name").html(data[i]['markers_name']); $("#title-show-phone").html(data[i]['markers_phone']); $("#title-show-url").html(data[i]['markers_url']); $("#title-show-address").html(data[i]['markers_address']); $("#title-show-desc").html(data[i]['markers_desc']); $("#title-show-time-of-work").html(data[i]['markers_time']); } }); $('.loading').hide(); } function deleteMyLocation(selected_index){ if (confirm('Are you sure you want to remove entry?')) { tbSaveLocation.splice(selected_index, 1); localStorage.setItem("tbSaveLocation", JSON.stringify(tbSaveLocation)); //alert("Client deleted."); listMyLocation(); } } function addMarkers(lon,lat,icon){ if(icon){ icon = urlRequest+"images/pin/"+icon; }else{ icon = "img/pin/pin2.png"; } var getLocation = new google.maps.LatLng(lat,lon); map.setCenter(new google.maps.LatLng(lat, lon)); map.setZoom(15); var marker = new google.maps.Marker({ map: map, icon: icon, position: getLocation, animation: google.maps.Animation.DROP, title: "test" }); markers.push(marker); } function getMyLocationMap(lon,lat){ setTimeout('init("false")',2500); setTimeout('addMarkers('+lon+','+lat+')',2500); } function getShowLocation(lon,lat,icon){ window.location.href = "#page_location_map"; setTimeout('init("false")',2500); setTimeout('addMarkers('+lon+','+lat+',"'+icon+'")',2500); } function getStreetView(lon,lat){ window.location.href = "#page_location_map"; setTimeout('init("false","","true")',2500); streetPlace = new google.maps.LatLng(lat, lon); } function getMyPlace(){ var url = newUrlRequest+"?act=getMyPlace&lon="+myLong+"&lat="+myLat; getRequest(url, function(data){ var data = JSON.parse(data.responseText); if(data.answer == 1){ $("#form-title").attr("value", data.name); $("#form_add_place").append(data.code); } }); }