询问在php laravel中引用google地图,点击显示周围目标点的问题。
具体代码如下,部分前端等省略
GetMemberMeStationNearStationController.php
public function __invoke(Request $request, int $id): JsonResponse
{
$castedParams = self::getCastedParams(self::$casts, $request->all());
$providerId = $request->user->provider->id;
$centerStation = EloquentStationRepository::findOneByParams([
'id' => $id,
'provider_id' => $providerId
]);
if (is_null($centerStation)) {
throw new ModelNotFoundException();
}
$nearStations = EloquentStationRepository::findNearStation(
$providerId,
$centerStation,
$castedParams
);
if ($nearStations->isNotEmpty()) {
$stationIds = $nearStations->pluck('id')->toArray();
$favoriteStations = EloquentFavoriteStationRepository::getAllByMemberIdAndStationIds($request->user->id, $stationIds);
$this->setFavoriteFlag($nearStations, $favoriteStations);
}
return new JsonResponse(
NearStationResource::collection($nearStations),
JsonResponse::HTTP_OK,
[self::ADDITIONAL_RESPONSE_HEADER_TOTAL_COUNT => (string) count($nearStations)]
);
}
EloquentStationRepository.php
public static function findNearStation(int $providerId, Station $centerStation, array $castedParams): Collection
{
$now = _getDate();
$currentPoint = new Point($centerStation->location->getLat(), $centerStation->location->getLng());
return Station::select([
'*',
DB::raw("ST_DistanceSphere(location, ST_GeomFromText('" . $currentPoint->toWKT() . "', 4326)) as distance_from_station")
])
->when(isset($castedParams['current_latitude'], $castedParams['current_longitude']), function ($query) use ($castedParams) {
$requestPoint = new CustomPoint($castedParams['current_latitude'], $castedParams['current_longitude']);
$query->selectRaw("ST_DistanceSphere(location, ST_GeomFromText('" . $requestPoint->toWKT() . "', 4326)) as distance_from_current");
})
->where('id', '<>', $centerStation->id)
->where('provider_id', $providerId)
->where('opened_at', '<=', $now)
->where(function ($query) use ($now) {
$query->where('closed_at', '>=', $now)
->orWhereNull('closed_at');
})
->whereRaw("ST_DWithin(location, ST_GeomFromText('" . $currentPoint->toWKT() . "', 4326)::geography , 19957)")
->where('is_member_station_map_displayable', true)
->whereHas('bexDeviceStatuses', function ($query) {
$query->where('comunit_status', ComunitStatus::OPEN()->getValue());
})
->orderBy('distance_from_station', 'asc')
->limit(config('service.near_station.limit'))
->get();
}
这样一来的确可以显示周围的"Station"点,但是出现一个问题,$centerStation变量中的点不被显示,
所以想请教,如何在触发地图中更新