Skip to content

Polymer element for client geolocation lookup with freegeoip.net

License

Notifications You must be signed in to change notification settings

HTMLElement/freegeoip-lookup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

polymer-freegeoip-lookup

Polymer element for client geolocation lookup with freegeoip.net

Install

bower install --save polymer-freegeoip-lookup

Usage

<link rel="import" href="freegeoip-lookup.html">
<freegeoip-lookup></freegeoip-lookup>
<script type="text/javascript">
  let el = document.querySelector('freegeoip-lookup');
  el.addEventListener('response-changed', (response) => {
    if(el.error) {
      alert('There was an error getting your location. Check your Ad-Blocker.');
    } else {
      alert('Freegeoip.net thinks you are at ' + el.response.latitude + ',' + el.response.longitude);
    }
  });
</script>

Configuration

The component can be configured via attributes on the HTMLElement.

Option Default Description
url https://freegeoip.net/json lookup url, self-host freegeoip
disable-autoload false does not automatically fire lookup on-load

By calling the element's lookup() function a new request is sent to the IP lookup API. Changing the url attribute at runtime does not automatically trigger a new request.

Output

Attribute Description
response An Object containing the server response. { latitude: 12, longitude: 34 }
error Boolean value that is true, if there was an error requesting the location
loading Boolean value that is true during active lookups

Events

  • response-changed
  • loading-changed
  • error-changed
document.querySelector('freegeoip-lookup').addEventListener('response-changed', doSomething);

Demo

About

Polymer element for client geolocation lookup with freegeoip.net

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages