62 lines
1.4 KiB
PHP
62 lines
1.4 KiB
PHP
|
<?php
|
||
|
|
||
|
require_once 'bootstrap.php';
|
||
|
|
||
|
$locationId = $_GET['locationId'];
|
||
|
$file = file_get_contents(LOCATIONS_FILE);
|
||
|
$locations = array();
|
||
|
|
||
|
foreach(explode("\n", $file) as $address){
|
||
|
|
||
|
$address = trim($address);
|
||
|
if($address==''){
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
$location = new stdClass;
|
||
|
$location->adr = $address;
|
||
|
$location->lat = '';
|
||
|
$location->lng = '';
|
||
|
$location->dst = '';
|
||
|
$location->id = '';
|
||
|
|
||
|
$row = dbGetRow("select * from df_locations where address='".dbEscape($address)."' limit 1 ");
|
||
|
if($row){
|
||
|
|
||
|
$location->id = $row->id;
|
||
|
$location->lat = $row->latitude;
|
||
|
$location->lng = $row->longitude;
|
||
|
$location->dst = getDbDistance($locationId, $location->id);
|
||
|
|
||
|
}
|
||
|
|
||
|
if(!$row and $_REQUEST['geosrc']=='db'){
|
||
|
|
||
|
list($city, $countrycode) = explode(',', $address);
|
||
|
$row = dbGetRow("select * from df_geocities where city='".dbEscape($city)."' and countrycode='".trim($countrycode)."' order by population desc limit 1 ");
|
||
|
if($row){
|
||
|
$location->lat = $row->latitude;
|
||
|
$location->lng = $row->longitude;
|
||
|
dbInsert('df_locations', array(
|
||
|
'address' => formatAddress($address),
|
||
|
'latitude' => $location->lat,
|
||
|
'longitude' => $location->lng,
|
||
|
));
|
||
|
$location->id = dbGetInsertId();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
$locations[] = $location;
|
||
|
|
||
|
}
|
||
|
|
||
|
echo json_encode($locations);
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|