• Problems

    This line enable URL Rewriting . It must be enabled via the RewriteEngine directive! and if your .htaccess file is going to use rewrite rules, you should always include this line. Otherwise, you can’t be sure if its enabled or not. The string “on” is case insensitive.

HTML5 enable us to get user location through it API Geolacation. Geolocation allows your visitors to
share their current location.
Depending on how they’re visiting your site, their location may be determined by
any of the following:
¦ IP address
¦ wireless network connection
¦ cell tower
¦ GPS hardware on the device
Which of the above methods are used will depend on the browser, as well as the
device’s capabilities. The browser then determines the location and passes it back
to the Geolocation API. One point to note, as the W3C Geolocation spec states: “No
guarantee is given that the API returns the device’s actual location.”

Geolocation is supported in:
¦ Safari 5+
¦ Chrome 5+
¦ Firefox 3.5+
¦ IE 9+
¦ Opera 10.6+
¦ iOS (Mobile Safari) 3.2+
¦ Android 2.1+

In this tutorial we will get user longitude and latitude.This information can be used for displaying location on google map etc.
STEP FOR GETTING USER LOCATION:
1)Check whether Geolocation is supported by their browser.
2)IF supported then retrive the current location
3)Extract longitude and latitude of user

STEP 1 :CHECKING WHETHER GEOLOCATION IS SUPPORTED OR NOT:

function determineLocation() {
if (Modernizr.geolocation) {
//geolocation is  supported in this browser
}
else {
// geolocation is not supported in this browser
}
}
Let’s examine this line by line:
We declare a function called determineLocation to contain our locationchecking
code.
We check the Modernizr object’s geolocation property to see whether geolocation
is supported in the current browser.  If geolocation is supported, we
execute code inside if statement, which is inside the if statement. If geolocation is
unsupported, we move on to the code inside the else statement.

STEP 2:IF SUPPORTED RETRIVE THE CURRENT LOCATION:


if (Modernizr.geolocation) {
navigator.geolocation.getCurrentPosition(displayOnMap);
}

The getCurrentPosition method takes one, two, or three arguments. Here is a
summary of the method’s definition from the W3C’s Geolocation API specification:4
void getCurrentPosition(successCallback, errorCallback, options);
Only the first argument, successCallback, is required. successCallback is the
name of the function you want to call once the position is determined.
In our example, if the location is successfully found, the displaycoordinate function
will be called with a new Position object. This Position object will contain the
current location of the device.

STEP 3: EXTRACTION OF USER LOGITUDE AND LATITUDE:-
function displaycoordinate(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
}

The first line of our function grabs the Coordinates object from the Position object
that was passed to our callback by the API. Inside the Coordinates object is the
property latitude, which we store inside a variable called latitude. We do the
same for longitude, storing it in the variable longitude.

No comments:

Post a Comment