Get latitude and longitude from the gps device with php


How to get latitude and longitude of gps device with PHP? and not through javascript. Thank you.

If you are using linux its rather simple to talk with a GPS over serial port... Just connect your GPS with a serial cable and activate the NMEA protocol in the GPS.

exec("stty -F /dev/ttyS0 9600 raw"); // Set the serial port parameters
if ( !$t = fopen('/dev/ttyS0','r+b') ) // Open for read
    die(" - Failed to open\n");

// Send some command...

while(true) {
    echo "recived: ".fgets($t,1024);

NMEA data looks like this: $GPGLL,4916.45,N,12311.12,W,225444,A,*1D

There are a lot of sites that describes how to the NMEA protocol works, for example