I am trying to make an app that finds a user's location, and then alerts them how far they are from a fixed location. I am new to JavaScript, and I'm having a lot of trouble trying to figure it out. The part that I cannot figure out is how to get the user's location in for the variable lat1 and lon1. I have researched how to just figure out the user's longitude and latitude, but all I can find is stuff about the getCurrentPosition() command. The only problem with this is that I don't want the values returned when they are found. Is their anyway that I could somehow achieve this? My code is below:
var lat2 = 45.843295;
var lon2 = -87.020821; // 2 is location
var lat1 =
var lon1 =
var R = 3963.1676; // radius in mi
var x1 = lat2-lat1;
var dLat = x1.toRad();
var x2 = lon2-lon1;
var dLon = x2.toRad();
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) *
Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
var TellMe= function(){
alert("You are"+" "+d+" "+"miles away from our school")
};
lon1 and lat1 are supposed to be the user's location.