<!DOCTYPE html> <html> <head><title>附近营业厅</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;"> <script src="<?php echo Yii::$app->getRequest()->baseUrl . '/../vendor/bower/jquery/dist/jquery.min.js'; ?> "></script> <script src="<?php echo Yii::$app->getRequest()->baseUrl . '/../vendor/bower/bootstrap/dist/js/bootstrap.min.js'; ?> "></script> <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=<?php echo MMapApi::getJsak(); ?> "></script> <!-- <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=s6ypC3XmgZkknuK8GGjk3xsF"></script> --> <script type="text/javascript"> $(document).ready(function(){ var lat = "<?php echo $lat_end; ?> "; var lng = "<?php echo $lon_end;
public static function getNearestOffices($gh_id, $lon, $lat) { $key = __METHOD__ . "{$gh_id}_{$lon}_{$lat}"; $value = Yii::$app->cache->get($key); if ($value !== false) { return $value; } $map = new MMapApi(); $rows = MOffice::find()->where(['gh_id' => $gh_id])->asArray()->all(); foreach ($rows as $key => &$row) { if ($row['lon'] < 1) { unset($rows[$key]); continue; } $row['distance'] = $map->getDistance($lon, $lat, $row['lon'], $row['lat']); } unset($row); \yii\helpers\ArrayHelper::multisort($rows, 'distance'); Yii::$app->cache->set($key, $rows, YII_DEBUG ? 10 : 5 * 60); return $rows; }