Get User's Current Location Info With jQuery - MapPin

| File Size: | 5.37 KB |
|---|---|
| Views Total: | 2 |
| Last Update: | |
| Publish Date: | |
| Official Website: | Go to website |
| License: | MIT |
MapPin is a jQuery plugin to get the user's current location info using jQuery, Browser Geolocation, and ipinfo & ip-api API.
Location Info The Plugin Tracks:
- Longitude
- Latitude
- Local IP
- City
- Region
- Country
- Timezone (Requires IP-API's premium plan when running on SSL)
- And Much More
How to use it:
1. Load the main JavaScript map.js in the document (jQuery library is included).
<script src="MapPin/map.js"></script>
2. An example app showing your user's current location info.
let info = requestLocation();
let showInfo = function showInfo() {
document.body.innerHTML =
"<h1 style='font-weight:bolder;'><br/>"+
"Longitude: "+info.longitude+"<br/>"+
"Latitude: "+info.latitude+"<br/>"+
"Local ip: "+info.localip?.ip+"<br/>"+
"Timezone: "+info.timeinfo.timezone+
"<br/>city: "+
info.localip?.data.city+
"<br/>region: "+info.localip?.data.region+
"<br/>Country: "+info.localip?.data.country+
"<br/></h1>";
};
<button onclick="showInfo();">Show My Info</button>
3. The output:
Longitude: -95.712891 Latitude: 37.09024 Local ip: 38.39.xxx.xxx Timezone: America/Los_Angeles city: Los Angeles region: California Country: US
4. Main functions:
/*
Output: Boolean (true | false);
Description: "
Returns true if the browser has a built in 'navigator.geolocation' api.
"
*/
browserSupportsGeolocation();
/*
Output: Boolean (true | false);
Description: "
Returns true if the browser has a version of RTCPeerConnection.
"
*/
browserSupportsPeerConnection();
/*
Output: class (RTCPeerConnection);
Description: "
Gets the browser's RTCPeerConnection class, if there is one.
"
*/
browserPeerConnection();
/*
Output: Object (An overview of all the location info the browser can gather {...}).
Description: "
Asks the browser for all the information it could possibly gather, then returns an object that
contains the data from every other function, plus some.
"
*/
requestLocation();
/*
Ougpug: Object (blank {});
Description: "
Returns a blank object that gets a new IP every time the IP address changes (to a new *private* IP).
"
*/
requestIPAddress();
/*
Output: Object (local (public) IP information);
Description: "
Returns local/public IP, plus the city, region, country, etc... of the user.
"
*/
requestLocalIPAddress();
/*
Output: Object (locql information);
Description: "
Returns basic information of the user, similar to requestLocalIPAddress.
"
*/
requestLocalInfo();
/*
Output: Object (time info);
Description: "
Returns an object with the timezone (and current time of the user in a future update).
"
*/
requestUserTime();
This awesome jQuery plugin is developed by CalinZBaenen. For more Advanced Usages, please check the demo page or visit the official website.











