简体   繁体   中英

get latitude and longitude from 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...
fwrite($t,"Command\n");

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 http://www.gpsinformation.org/dale/nmea.htm

I do not think it is possible, all the commercial GPS modules shield the raw data (NMEI) from the user. Now, if you only want latitude and longitude data for a specific place, you do not need a GPS. You can use Google Maps for that, if you want to use PHP, check out the API's provided by ESRI ( http://www.esri.com/ ), NAVTEQ I used them long back and they were pretty good. Now, if you want to use Lat and Long data on the field you might want to consider buying a GPS logger (if you want RAW NMEI data) it can tell you all kind of awesome things. If you just want Lat and Long info, your Garmin or Tom Tom should be good enough. Again, it all depends on what you want and how you want.

/srm

You can use Google Maps API .

I know this French source with a code example easy to understand: Geolocation in 5 lines of PHP .

But I don't know how you can retrieve the names of cities and countries from your GPS device.

Really need to know more about what hardware you are using. I've done a lot of work with GPS in the past, and a lot of GPS units will give you the GPS data in the standard NMEA data format, typically across a RS232 serial interface, at about 1Hz. NMEA doesn't give you all the fancy advanced data like ephemeris (with which you can start to really do some interesting things).

You said you're running php on the 'device', so assuming the GPS data is coming across a serial/usb interface, and the GPS chip is giving you NMEA data, then you'll need to get that data from the serial port. PHP does have a direct IO library you can use ( http://us2.php.net/manual/en/intro.dio.php ). Check out this post for more details Serial comm with PHP on Windows . If the processor to GPS interface is not serial/usb I've no idea how you're going to get that into php land.

Hope that helps. Maybe you can give us more info on the hardware you're using?

Answer is simple, it is not possible with PHP. You should use any of the client scripting language if the client browser support this feature.

However, some sort of information you can get using the visitor IP address. But this may not be giving the exact location, it only gives the location of the ISP. (Google Analytics uses this method to get visitor location), also you need a big DB for IP to location information or you need to get some FREE/Paid service giving location info from IP address.

Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM