14

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

  1. 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,
                                                                                )
                             )));   
    

    }

  2. 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?

sumit
  • 15,003
  • 12
  • 69
  • 110
  • I think you can limit the number of concurrent processes through supervisor's config setting `numprocs=8`. Not entirely sure if that's what your looking for though. –  Jun 17 '17 at 01:56
  • I see a few ways to you can improve this at least, but to give you a few pointers: 1) you could check if a job is still (waiting) on the queue for a vehicle and get rid of any pending jobs for a vehicle when you put a new job on the queue 2) you probably don't want to do a call to google api each time. For instance, consider checking if the coordinates are still the same, because if that is the case, the vehicle hasn't moved and you already know the location. – Leentje Jul 10 '17 at 09:30
  • 3
    On second thought; I'd only do the API call to google when the frontend needs to show the actual location. (And just save the coordinates) – Leentje Jul 10 '17 at 09:33
  • 1
    Usuage of google api has the limit per day and per second so by hitting the api on demand(when ever we need to display on front end and saving the coordinates in db). – SNG Oct 17 '17 at 05:57
  • Does it make sense to hammer the Google API, or would it make sense to have local calls to reverse geocode locations? See http://download.geonames.org/export/dump/ or https://zipcodedownload.com - I suppose the answer can come down to how accurate of a result do you need? – Rob W Oct 25 '17 at 15:35

2 Answers2

1

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:

  • Always store the coordinates
  • Run the API calls only when he/she/someone is in that page
  • Use a priority system for GPS coordinates in the viewed area of the screen (viewed map boundaries at frontent)
  • Run low priority coordinates on a best effort window (based on API availability, usage limit, etc), maybe even on a secondary API for non-priority

Btw we're using HereMaps, it's payed but you can create a demo/test account for 3 months.

0

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.

Markus
  • 440
  • 2
  • 10