Search code examples
phpgoogle-mapsgpstracking

How to create a very basic php script for users to login and see the location of their vehicles


My question is actually related with a basic car tracking web application. My customers have 1 or more GPS devices registered for their accounts which are integrated to their vehicles.

I can send data to anywhere with GET format from GPS devices. Each GPS device has its own unique identifier code.

I want to put a very basic php page to make my customers able to login with their username & password to see their registered gps devices. And when they click one of them; they should be able to see the records coming from their site GPS devices and use a google map api to see coordinates in a small map.

Is there any way to put this script off the shelf or do someone can show me a way to make it basicly?


Solution

  • You can follow this Quick-start sample app for PHP on how the user can Sign In using their username and password.

    Accoring also to this tutorial, first you need client id and secret key from Google API. Go to Google API console and create an OAuth client for Web Application. Next you will be presented with your Client ID and Secret, which will be required in code below.

    ### Google Settings.Client ID, Client Secret from https://console.developers.google.com ###
    $client_id = 'xxxxxxxxxxxxxxxxxx'; 
    $client_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
    $redirect_uri = 'http://path-to-script/google-login-api/';
    

    When user clicks Google login link, user is redirected to Google Authentication page, once user grants the basic permission to your application, user is redirected back to your website with Authentication code. The code is than used to obtain Access Token, using Access Token the application can access current user data from Google, which could be used to register and login the user.

    Next, for the user to see their registered gps devices, use Google Maps Roads API to identify the roads a vehicle was traveling along and provides additional metadata about those roads, such as speed limits.

    A request to snap to road must be sent via HTTPS, and takes the following form: https://roads.googleapis.com/v1/snapToRoads?parameters&key=YOUR_API_KEY

    For each valid request, the Google Maps Roads API will return a response in the format indicated within the request URL. Example element that may be present in a Snap to Roads response is the location that contains a latitude and longitude value.

    Here is the sample request and response from the documentation.

    You may also check this example on GitHub.

    Hope this helps!