Add map for viewing nearby outlets in job order processing

This commit is contained in:
Kendrick Chan 2018-01-18 10:07:54 +08:00
parent 798dd5e599
commit bcfa77151c
2 changed files with 29 additions and 4 deletions

View file

@ -35,7 +35,7 @@ class MapTools
foreach ($outlets as $outlet)
{
$coord = $outlet->getCoordinates();
$dests[] = $coord->getLatitude() . ',' . $point->getLongitude();
$dests[] = round($coord->getLatitude(),5) . ',' . round($point->getLongitude(), 5);
}
$dests_value = implode('|', $dests);
@ -48,6 +48,8 @@ class MapTools
'destinations' => $dests_value,
];
error_log(print_r($gmaps_params, true));
// query google maps api
$res = $client->request('GET', $maps_url, ['query' => $gmaps_params]);
@ -69,7 +71,7 @@ class MapTools
$final_data = [];
foreach ($result as $row)
{
// error_log($row[0]->getName() . ' - ' . $row['dist']);
error_log($row[0]->getName() . ' - ' . $row['dist']);
$outlets[] = $row[0];
$final_data[] = [
'outlet' => $row[0],
@ -82,7 +84,7 @@ class MapTools
// get actual distance details with eta from google maps api
$raw_res = $this->mapGetDistances($point, $outlets);
$res = json_decode($raw_res, true);
// error_log(print_r($res, true));
error_log(print_r($res, true));
// check if status is ok
if ($res['status'] != 'OK')

View file

@ -366,6 +366,7 @@
</div>
</div>
</div>
<div id="outlet_map" style="height:600px;"></div>
{% endif %}
</div>
@ -447,10 +448,32 @@ $(function() {
}
});
// check if we need to set map
{% if mode == 'update' %}
// check if we need to set map
var latlng = new google.maps.LatLng({{ obj.getCoordinates.getLatitude }}, {{ obj.getCoordinates.getLongitude }});
selectPoint(map, latlng);
// display outlet map
var omap = new GMaps({
div: '#outlet_map',
lat: {{ obj.getCoordinates.getLatitude }},
lng: {{ obj.getCoordinates.getLongitude }}
});
omap.addMarker({
lat: {{ obj.getCoordinates.getLatitude }},
lng: {{ obj.getCoordinates.getLongitude }}
});
{% for outlet in outlets %}
omap.addMarker({
lat: {{ outlet.outlet.getCoordinates.getLatitude }},
lng: {{ outlet.outlet.getCoordinates.getLongitude }},
title: "{{ outlet.outlet.getName }}",
content: "{{ outlet.outlet.getName }}"
});
{% endfor %}
{% endif %}