findByPk($lewaimai_customer_id); if ($lewaimaicustomerModel) { //首先将获取到的GPS坐标,转换成高德系统的坐标 if ($is_gps) { $locationArray = LewaimaiCoordinate::GPStoAMAP($longitude, $latitude); } else { $locationArray[0] = $longitude; $locationArray[1] = $latitude; } //获取信息 $infoArray = LewaimaiCoordinate::GetPositionInfo($longitude, $latitude, $is_gps); if (!is_array($infoArray)) { $infoArray = array(); $infoArray["province"] = ""; $infoArray["city"] = ""; $infoArray["district"] = ""; $infoArray["address"] = ""; } //LewaimaiDebug::LogArray($infoArray); if (!$locationArray || !$infoArray) { return false; } $lewaimaicustomerModel->coordinate_x = $locationArray[1]; $lewaimaicustomerModel->coordinate_y = $locationArray[0]; $lewaimaicustomerModel->last_position_time = date("Y-m-d H:i:s"); $lewaimaicustomerModel->position_province = $infoArray["province"]; $lewaimaicustomerModel->position_city = $infoArray["city"]; $lewaimaicustomerModel->position_district = $infoArray["district"]; $lewaimaicustomerModel->position_address = $infoArray["address"]; if (!$lewaimaicustomerModel->update()) { LewaimaiDebug::LogModelError($lewaimaicustomerModel); return false; } return true; } return false; } //根据ip获取位置信息 /** { "address": "CN|广东|深圳|None|CHINANET|0|0", "content": { "address_detail": { "province": "广东省", "city": "深圳市", "district": "", "street": "", "street_number": "", "city_code": 340 }, "address": "广东省深圳市", "point": { "y": "2560682.35", "x": "12693451.44" } }, "status": 0 } */ public static function GetPositionByIp($ip) { $key = BaiduMap::getKey(); $url = file_get_contents("http://api.map.baidu.com/location/ip?ip=".$ip."&ak=".$key); $data = json_decode($url,true); if ($data && $data['status'] == 0) { return $data['content']; } return false; } }