Set url service app var urlRequest http locmap at admin var urlService

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
// 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('<li><img src="http://maps.googleapis.com/maps/api/staticmap?center='+myLat+','+myLong+'&markers=color:blue|label:S|'+myLat+','+myLong+'&zoom=15&size='+pw+'x220&sensor=false"></li>');
$("#page_home .slider ul").append('<li><img src="http://maps.googleapis.com/maps/api/streetview?size='+pw+'x230&location='+myLat+','+myLong+'&fov=90&heading=235&pitch=10&sensor=false"></li>');
});
// 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 = '<div class="infoWindow"><strong>' + location.markers_name + '</strong>'
+ '<br/>' + location.category_name
+ '<br/>' + location.markers_address + '</div>';
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("<li onClick='getLocationList("+data[i]['category_id']+")'><a transition='side' href='#page_detail'><div class='fs1' aria-hidden='true' data-icon='"+data[i]['category_icon']+"'></div><strong>"+data[i]['category_name']+"</strong><span class='chevron'></span><span class='count'>"+data[i]['count']+"</span></a></li>");
}
});
}
// 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("<li onClick='detailShowLocation("+data[i]['markers_id']+")'><a transition='side' href='#page_show_location'><strong style=\"float:left;margin-right: 10px;\">"+data[i]['markers_name']+"</strong><span id=\"active-"+data[i]['markers_id']+"\"></span><p>"+data[i]['markers_address']+"</p><span class='chevron'></span></a></li>");
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 = '<span class="icon-time-onn"></span>';
} else {
var active = '<span class="icon-time-off"></span>';
}
} else {
var time_line = 0;
var active = '<span class="icon-time-off"></span>';
}
$("#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("<li onClick='detailShowLocation("+data[i]['markers_id']+")'><a transition='side' href='#page_show_location'><strong>"+data[i]['markers_name']+"</strong><p>"+data[i]['markers_address']+"</p><span class='chevron'></span></a></li>");
}
});
}
// 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("<li class='list-dividers'>Near "+address+"</li>");
for (var i = 0; i < data.length; i++) {
var logo = urlRequest+"/upload/logo/"+data[i]['markers_logo'];
$('#list-nearby').append("<li onClick='detailShowLocation("+data[i]['markers_id']+")'><a transition='side' href='#page_show_location'><strong>"+data[i]['markers_name']+"</strong><p>"+data[i]['markers_address']+"</p><span class='distance'>"+data[i]['distance']+" "+ distances +"</span><div class='img-box'><img src='"+logo+"' width='60' height='60'></div></a></li>");
}
});
}
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("<li><span onClick='detailListMyLocation("+data.id[i]+")'><strong>"+data.title[i]+"</strong><p>"+date.toLocaleString()+"</p></span></li>");//<a onClick='deleteMyLocation("+i+");' class='button-negative'>Delete</a>
}
});
}
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('<li><img src="http://maps.googleapis.com/maps/api/staticmap?center='+data.lat+','+data.lng+'&markers=color:blue|label:S|'+data.lat+','+data.lng+'&zoom=15&size='+pw+'x220&sensor=false"></li>');
$("#page_detail_save_location .slider ul").append('<li><img src="http://maps.googleapis.com/maps/api/streetview?size='+pw+'x230&location='+myLat+','+myLong+'&fov=90&heading=235&pitch=10&sensor=false"></li>');
$("#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('<a onClick="getMyLocationMap('+data.lat+','+data.lng+')" class="button-positive button-block" href="#page_location_map">Map View</a>');
$("#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('<li><img src="'+urlRequest+'upload/images/'+dataImages[i]['images_url']+'"></li>');
}
});
$('#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);
}
});
}