I don’t quite understand how you’re gonna use the Googlemaps API with C#, will probably be a webView
, I won’t go into details because the webView
can be something Desktop or Windowsphone (or other type of device), by the tag Asp-net-mvc suppose it is web, maybe after I edit it.
If it is really web Asp.net-mvc is only the "back-end" part, in case I’m going for an example then just javascript to use Google-Maps from the initial position of the user, see an example in the documentation itself:
You’ll have to use navigator.geolocation.getCurrentPosition
to obtain the user’s position.
Notes:
<!DOCTYPE html>
<html>
<head>
<title>Geolocation</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 1
});
var infoWindow = new google.maps.InfoWindow({map: map});
// Try HTML5 geolocation.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
infoWindow.setPosition(pos);
infoWindow.setContent('Location found.');
map.setCenter(pos);
}, function() {
handleLocationError(true, infoWindow, map.getCenter());
});
} else {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow, map.getCenter());
}
}
function handleLocationError(browserHasGeolocation, infoWindow, pos) {
infoWindow.setPosition(pos);
infoWindow.setContent(browserHasGeolocation ?
'Error: The Geolocation service failed.' :
'Error: Your browser doesn\'t support geolocation.');
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&signed_in=true&callback=initMap"
async defer>
</script>
</body>
</html>
I believe you only need HTML Geolocation to get the coordinates from the client’s browser, and set those to the center of the map, that link shows how to use, not very precise, but already helps
– jbrunoxd