Get latitude and longitude from gps device using php

How to get latitude and longitude of GPS device with PHP? not through javascript. Thanks.

+4
source share
5 answers

If you are using linux, it is quite simple to talk to GPS via the serial port ... Just connect your GPS using a serial cable and activate the NMEA protocol in 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 is as follows: $GPGLL,4916.45,N,12311.12,W,225444,A,*1D

There are many sites that describe how the NMEA protocol works, for example http://www.gpsinformation.org/dale/nmea.htm

+3
source

I do not think it is possible, all commercial GPS modules protect raw data (NMEI) from the user. Now, if you only need latitude and longitude data for a specific location, you do not need GPS. You can use Google Maps for this, if you want to use PHP, check out the API provided by ESRI ( http://www.esri.com/ ), NAVTEQ I used them a long time ago, and they were pretty good. Now, if you want to use Lat and Long data in the field, you may want to buy a GPS logger (if you want RAW NMEI data), it can tell you all kinds of amazing 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

0
source

You can use the Google Maps API .

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

But I do not know how you can get the names of cities and countries from your GPS device.

0
source

In fact, you need to know more about what equipment you use. In the past, I did a lot of work with GPS, and many GPS devices will provide you GPS data in the standard NMEA data format, usually via the RS232 serial interface, at about 1 Hz. NMEA doesn't give you all the fancy cutting-edge data like ephemeris (with which you can start to really do interesting things).

You said that you use php on the “device”, therefore, given that the GPS data is received via the serial / usb interface, and the GPS chip gives you NMEA data, then you will need to get this data from the serial port. PHP has a direct IO library that you can use ( http://us2.php.net/manual/en/intro.dio.php ). Read this post for more details Serial Comm with PHP on Windows . If the processor to the GPS interface is not serial / usb, I don't know how you are going to get it on php lands.

Hope this helps. Maybe you can give us more information about the hardware that you use?

0
source

The answer is simple, this is not possible with PHP. You must use any client scripting language if the client browser supports this feature.

However, you can get some information using the visitor’s IP address. But this may not give the exact location, it only gives the location of the provider. (Google Analytics uses this method to get the visitor’s location), you also need a large database for the IP address, or you need to get a FREE / paid service by specifying the location information from the IP address.

Hope this helps!

0
source

All Articles