Pen Settings



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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


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


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.


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.


                <h1>Sorting a list of locations by how for away they are: Part 3</h1>
<p>In <a href="">the previous codepen</a>, we used the <a href="
	">Haversine formula</a> to figure out how many kilometers away each UW system campus is. In this example, we are going to sort by distance away from the campus.</p>

<div id="app">
	It looks like you are currently at:<br /><br />
	{{location.street}}<br />
	{{location.adminArea5}}, {{location.adminArea3}} {{location.postalCode}}<br /><br />
	Where the University of Wisconsin System campuses are at:<br /><br />
			<th>Distance Away</th>
		<tr v-for="campus in sortedCampuses">
			<td>{{campus.distance}} km</td>




                new Vue({
  el: "#app",
  data() {
    return {
			location: null,
			campuses: [{name:'UW-Milwaukee',address: '2200 E Kenwood Blvd, Milwaukee, WI 53201',lat:43.075210,long:-87.881470},{name:'UW-Oshkosh',address: '800 Algoma Blvd. Oshkosh, WI 54901',lat:44.026360,long:-88.551500},{name:'UW-Green Bay',address: '2420 Nicolet Dr, Green Bay, WI 54311',lat:44.532299,long:-87.919853},{name:'UW-Parkside',address: '900 Wood Rd, Kenosha, WI 53144',lat:42.646120,long:-87.856200},{name:'UW-Whitewater',address: '800 W Main St, Whitewater, WI 53190',lat:42.834970,long:-88.742950}]
	methods: {
		getDistanceFromLatLonInKm: function(lat1,lon1,lat2,lon2) {
			var R = 6371; // Radius of the earth in km
			var dLat = this.deg2rad(lat2-lat1);  // deg2rad below
			var dLon = this.deg2rad(lon2-lon1); 
			var a = 
				Math.sin(dLat/2) * Math.sin(dLat/2) +
				Math.cos(this.deg2rad(lat1)) * Math.cos(this.deg2rad(lat2)) * 
				Math.sin(dLon/2) * Math.sin(dLon/2)
			var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
			var d = R * c; // Distance in km
			return d;
		deg2rad: function(deg) {
			return deg * (Math.PI/180)
		geolocation: function() {
      if (navigator.geolocation) {
			} else {
				console.log("Geolocation is not supported by this browser.");
		showPosition: function(position) {
			// Use Axios to make a MapQuest API Call
					.then(response=> (this.location =[0].locations[0]));
  mounted() {
	watch: {
		location: function(){
			// Loop over the campuses
			for (let i in this.campuses) {
				// Set the distance value in km
				this.campuses[i].distance = this.getDistanceFromLatLonInKm(this.campuses[i].lat,this.campuses[i].long,,this.location.latLng.lng);
	computed: {
		// This new computed value is how we are going to sort the campuses by how far they are from the user
		sortedCampuses: function() {
			// Temporary hold for 'this'
			var globalScope = this;

			function compare(a, b) {
				if (a.distance < b.distance)
					return -1;
				if (a.distance > b.distance)
					return 1;
				return 0;
			return this.campuses.sort(compare);