Do you mean to add this code next to the previous code? Like this
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=API_Key"></script>
<script type="text/javascript">
function ViewCoOrdinate() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (p) {
var lat = p.coords.latitude;
var lng = p.coords.longitude;
document.getElementById("txtLat").value = lat;
document.getElementById("txtLon").value = lng;
});
} else {
alert('Geo Location feature is not supported in this browser.');
}
return false;
}
</script>
navigator.geolocation.getCurrentPosition(
function (position) {
document.getElementById("txtLat").value = position.coords.latitude;
document.getElementById("txtLon").value = position.coords.longitude;
},
function (error) {
alert(error.code + ": " + error.message);
},
{
enableHighAccuracy: true,
maximumAge: 10000,
timeout: 5000
}
);
<input type="text" id="txtLat" />
<input type="text" id="txtLon" />
<input type="button" id="btnView" value="View" onclintclick="return ViewCoOrdinate()" />