Xerting
Xerting

Reputation: 91

How to determine my current location (longitude & latitude)?

I currently have php website that I want to be able to find the users current location and then pass that through the url in a format similar to:

page.php?lon=2312313&lat=sdfsdsf

Any ideas on how I can do this?

Upvotes: 2

Views: 7042

Answers (4)

Kushal
Kushal

Reputation: 3168

If you know to identify location name using Google Maps API by supplying latitudes and longitudes, the page that will locate the users is likely to have

<script src="http://maps.google.com/maps/api/js?sensor=true"></script>

in its head section

The parameter sensor=true suggests that target device has a GPS and the location info will supplied using GPS, as not all mobile web browsers support geolocation. But I'm not sure if this will use BTS (Base Transceiver Station) of mobile service provider to obtain approximate location in case GPS device is not available on phone. Note that entire operation will work using JavaScript instead of PHP.

Upvotes: 1

rob
rob

Reputation: 10119

If the browser supports geolocation, you can do this:

if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(success, error);
}

This is an html5 thing, and it will prompt the user the first time to give the site permission to access your location.

Of course this is a javascript thing (not php)

Upvotes: 1

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385108

Nothing automatic (thank god). You'd be relying on the client to be able to interact with some local GPS device and provide position data. Heavily technology specific.

Upvotes: 2

Bil
Bil

Reputation: 543

You can use GeoIP PHP library but it's not very accurate.

Upvotes: 0

Related Questions