I have about 100 GPS device sending coordinates periodically on every 10 seconds . My customer want real time reverse geocoding to see his vehicles along with location on a tabular view. I have set up a queue to save all those packets in db before where I have added geocoding script like below
Receive TCP IP message using websocket
public function onMessage(ConnectionInterface $conn, $msg) {
//get the message
// send the dispatch job to save it in db
$this->dispatch(new SavePacketsToDb($key_1, json_encode(
array(
'company_id' => $key_1,
'vehicle_id' => $company->vehicle_id,
'tracker_id' => $company->tracker_id,
'lat' => $lat,
'lng' => $lng,
'imei' => $imei,
'datetime' => $datetime,
)
)));
}
Run a queue
public function handle(){
$lat=$obj->lat;
$lng=$obj->lng;
$url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" . $lat . "," . $lng . "&key=mykey";
$json = file_get_contents($url);
$data = json_decode($json);
$status = $data->status;
$address = '';
if ($status == "OK") {
// echo "from geocode address";
echo $address = $data->results[0]->formatted_address;
}
else{
$address=NULL;
}
//save to db
}
I am just worried if it works for 1000 concurrent devices if I include this geocoding on queue, is there any better approach for it?
We developed something similar, initially with google maps api but i moved away because it was not so accurate in my location (Brazil).
For google maps, if you dont notice any problems with accuracy you could run up a queue and process the data but with a limited amount per day (notice the 2500 lookups limit i believe) for free service or buy the required lookups.
If you need real-time of all devices, you will need to pay for larger volume in google maps and i would use a queueing service for it. We are using RabbitMQ Queue to receive the coordinates and then we have small clients/workers that get items from the queue and process them (there are other APIs involved).
I dont believe your customer will be all day long in front of that screen, so maybe you can:
Btw we're using HereMaps, it's payed but you can create a demo/test account for 3 months.
I think reverse geocode each coordinate is quite inefficient. I would rather try to group some coordinates in some packages and the use something like the thephpleague/geotools batch api to reverse geocoding this data, if they are requested.
And i would not rely only on google maps. I think a good advice is to have a fallback, because google maps does not know each address and you can quit easy in the rate limit (with such amount of data). Have a look at the [geocoder-php/Geocoder] package, which supports many geocoding services.
Mabye a site note: I'm one of the people who maintain this project.