here you go: EDIT:
   var x = document.getElementById("demo");
var locationx = new google.maps.LatLng(-7.2574719, 112.7520883);
latlng = locationx;
var myLocation;
function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function (position) {
      latOn = position.coords.latitude;
      longOn = position.coords.longitude;
      document.getElementById('lat').value = latOn;
      document.getElementById('long').value = longOn;
      myLocation = { latOn: latOn, longOn: longOn };
    }, showError);
  }
  else {
    x.innerHTML = "Geolocation is not supported by this browser.";
  }
}
Now every change of the location the variable myLocation will be the new location
If you want getLocation to return a value use:
var x = document.getElementById("demo");
var locationx = new google.maps.LatLng(-7.2574719, 112.7520883);
latlng = locationx;
var myLocation = getLocation();
function getLocation() {
  if (navigator.geolocation) {
    var location;
    navigator.geolocation.getCurrentPosition(function (position) {
      latOn = position.coords.latitude;
      longOn = position.coords.longitude;
      document.getElementById('lat').value = latOn;
      document.getElementById('long').value = longOn;
      location = { latOn: latOn, longOn: longOn };
    }, showError);
  }
  else {
    x.innerHTML = "Geolocation is not supported by this browser.";
  }
  if (location) {
    return location;
  }
}