Example #1
0
 /**
  * @param LocationContract $location
  * @param int              $target
  * @return string
  */
 public static function url(LocationContract $location, $target = WebMapServiceContract::Target_PC)
 {
     $title = urlencode($location->getTitle());
     $lat = $location->getLatitude();
     $lng = $location->getLongitude();
     return "http://api.map.baidu.com/marker?location={$lat},{$lng}&title=" . $title . "&output=html&src=rollong|projects";
 }
 /**
  * @param LocationContract $location
  * @return $this
  */
 public function setLocation(LocationContract $location)
 {
     $this->longitude = $location->getLongitude();
     $this->latitude = $location->getLatitude();
     $this->location_precision = $location->getPrecision();
     $this->location_title = $location->getTitle();
     $this->save();
     return $this;
 }
Example #3
0
 /**
  * 距离(米)
  * @param LocationContract $location
  * @return float
  */
 public function getDistance(LocationContract $location)
 {
     //将角度转为狐度
     $radLat1 = deg2rad($this->getLatitude());
     $radLat2 = deg2rad($location->getLatitude());
     $radLng1 = deg2rad($this->getLongitude());
     $radLng2 = deg2rad($location->getLongitude());
     $a = $radLat1 - $radLat2;
     //两纬度之差,纬度<90
     $b = $radLng1 - $radLng2;
     //两经度之差纬度<180
     $s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))) * 6378137.0;
     return $s;
 }