Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>IP-based Geolocation</h1>
<p>This example uses <a href="https://vuejs.org/">Vue.js</a>, <a href="https://github.com/axios/axios">Axios</a>, <a href="https://developer.mapquest.com">a mapquest API</a>, and <a href="https://geoipify.whoisxmlapi.com/">GeoIPify</a>.  It should get your <a href="https://codepen.io/steinbring/pen/VwLWXON">current IP</a> address and query <a href="https://geoipify.whoisxmlapi.com/">GeoIPify</a> and <a href="https://www.mapquest.com">mapquest</a> for location details.

<div id="app">
	It looks like you ({{ip}}) are currently at:<br /><br />
{{details.street}}<br />
	{{details.adminArea5}}, {{details.adminArea3}} {{details.postalCode}}<br />
	
</div> 
              
            
!

CSS

              
                
              
            
!

JS

              
                new Vue({
  el: "#app",
  data() {
    return {
			ip: null,
			ipResponse: null,
			locationByIP: null,
			details: null
    };
  },
	mounted() {
		// Get the user's states from the cloudflare service
    axios
    .get("https://www.cloudflare.com/cdn-cgi/trace")
      .then(response=> (this.ipResponse = response.data))
  },
	watch: {
    // This should do a substring of the result returned by CloudFlare
    ipResponse: function (){
      this.ip = this.ipResponse.substring(this.ipResponse.search('ip=')+3, this.ipResponse.search('ts='));
			this.ip = this.ip.trim();
    },
		// This should get the lat/long of the user, based upon their IP address
		ip: function (){
			axios
				.get("https://ip-geolocation.whoisxmlapi.com/api/v1?apiKey=at_AZZUMyTYVvn0oJoaTdvrY2CRJeNAJ&ipAddress="+this.ip)
					.then(response=> (this.locationByIP = response.data.location));
		},
		// Now that we have the location based upon the IP address, let's ge their street address
		locationByIP: function(){
			axios
				.get("https://www.mapquestapi.com/geocoding/v1/reverse?key=TPWvRrsfpgGWBACqqXd94fbDcfVpy2WJ&location="+this.locationByIP.lat+"%2C"+this.locationByIP.lng+"&outFormat=json&thumbMaps=false")
					.then(response=> (this.details = response.data.results[0].locations[0]));
		}
  }
});
              
            
!
999px

Console