Excuse my ignorance, but it is in Java. I'm I able to grab the longitude and latitude into C# by some means?
No, the code is JavaScript which runs in the browser. C# cannot find the user location since C# runs on the server not the client. I assume you are building a browser based application. If not, then you are probably in the wrong forum and need maybe mobile
application support.
Hi,
its a shame that there is no way of capturing the values in to C# then.
As I would have liked to have done a comparison to see if the user using the phone was in the correct location, there abouts.
Hi,
its a shame that there is no way of capturing the values in to C# then.
As I would have liked to have done a comparison to see if the user using the phone was in the correct location, there abouts.
Thanks,
You misunderstand. If your C# application is built to run on a mobile device then certainly the mobile application can get the phone GPS location. Web API is a serer application. The code is running on the server not the mobile device. Therefore, the
mobile device must send the Web API application it's GPS location. This is simply how web application work.
Hang on a minute that was my original question.
Were on a ,NET forum which is mainly C#, VB.
In a sub section for API, APP.
How do I get the coordinates from some ones mobile device.
Thanks,
I think you misunderstand the web development fundamentals. Web API is a server technology and runs on a web server not a mobile application. The mobile application calls Web API and passes the location. The mobile application can be a browser in which
case see the link in my first post. Otherwise you are writing a mobile application that user will install on their mobile device.
The .NET System.Device.Location namespace has geo location APIs. But remember you don't want to put this code in the Web API because it will always show the server's location not the mobile application.
So, I can pass the coordinates from the mobile device to the Web App using the Java example?
Yes. But the language is JavaScript not Java! JavaScript is used to write code that runs in the browser; a browser application. Please see the following code example whihc I copied from the link in my first post.
@{
ViewData["Title"] = "Index";
}
<h1>Index</h1>
<button id="find-me">Show my location</button>
<br />
<p id="status"></p>
<a id="map-link" target="_blank"></a>
@section scripts {
<script>
function geoFindMe() {
const status = document.querySelector('#status');
const mapLink = document.querySelector('#map-link');
mapLink.href = '';
mapLink.textContent = '';
function success(position) {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
status.textContent = '';
mapLink.href = `https://www.openstreetmap.org/#map=18/${latitude}/${longitude}`;
mapLink.textContent = `Latitude: ${latitude} °, Longitude: ${longitude} °`;
}
function error() {
status.textContent = 'Unable to retrieve your location';
}
if (!navigator.geolocation) {
status.textContent = 'Geolocation is not supported by your browser';
} else {
status.textContent = 'Locating…';
navigator.geolocation.getCurrentPosition(success, error);
}
}
document.querySelector('#find-me').addEventListener('click', geoFindMe);
</script>
}
Use AJAX or a standard HTTP GET or POST to send the geo location to Web API. The design depends on how your application works which is unknown at this time.
Which line forwards the location to the App?
Just spotted text at bottom to answer this question.. Use AJAX or a standard HTTP GET or POST to send the geo location to Web API. The design depends on how your application works which is unknown at this time.
Accroding to your description,as far as I think,the getCurrentPosition() method is used to return the user's position.
If the getCurrentPosition() method is successful, it returns a coordinates object to the function specified in the success(Position).The success() function outputs the Latitude and Longitude.
Best regards,
Yijing Sun
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
25 Points
189 Posts
Mobile phone gps coordinates
Mar 13, 2020 09:51 AM|NewToDotyNet|LINK
Hi,
is it possible to get gps coordinates from some ones mobile phone when they are connected to your web app.
Thanks,
All-Star
52971 Points
23571 Posts
Re: Mobile phone gps coordinates
Mar 13, 2020 12:04 PM|mgebhard|LINK
See geolocation documentation.
https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API
Member
25 Points
189 Posts
Re: Mobile phone gps coordinates
Mar 13, 2020 02:37 PM|NewToDotyNet|LINK
Hi, looks good.
Excuse my ignorance, but it is in Java.
I'm I able to grab the longitude and latitude into C# by some means?
Thanks,
All-Star
52971 Points
23571 Posts
Re: Mobile phone gps coordinates
Mar 13, 2020 04:21 PM|mgebhard|LINK
No, the code is JavaScript which runs in the browser. C# cannot find the user location since C# runs on the server not the client. I assume you are building a browser based application. If not, then you are probably in the wrong forum and need maybe mobile application support.
Member
25 Points
189 Posts
Re: Mobile phone gps coordinates
Mar 13, 2020 08:07 PM|NewToDotyNet|LINK
Hi,
its a shame that there is no way of capturing the values in to C# then.
As I would have liked to have done a comparison to see if the user using the phone was in the correct location, there abouts.
Thanks,
All-Star
52971 Points
23571 Posts
Re: Mobile phone gps coordinates
Mar 13, 2020 09:31 PM|mgebhard|LINK
You misunderstand. If your C# application is built to run on a mobile device then certainly the mobile application can get the phone GPS location. Web API is a serer application. The code is running on the server not the mobile device. Therefore, the mobile device must send the Web API application it's GPS location. This is simply how web application work.
Member
25 Points
189 Posts
Re: Mobile phone gps coordinates
Mar 14, 2020 07:35 AM|NewToDotyNet|LINK
Hang on a minute that was my original question.
Were on a ,NET forum which is mainly C#, VB.
In a sub section for API, APP.
How do I get the coordinates from some ones mobile device.
Thanks,
All-Star
52971 Points
23571 Posts
Re: Mobile phone gps coordinates
Mar 14, 2020 09:48 AM|mgebhard|LINK
I think you misunderstand the web development fundamentals. Web API is a server technology and runs on a web server not a mobile application. The mobile application calls Web API and passes the location. The mobile application can be a browser in which case see the link in my first post. Otherwise you are writing a mobile application that user will install on their mobile device.
The .NET System.Device.Location namespace has geo location APIs. But remember you don't want to put this code in the Web API because it will always show the server's location not the mobile application.
https://docs.microsoft.com/en-us/dotnet/api/system.device.location.geocoordinatewatcher?view=netframework-4.8
Member
25 Points
189 Posts
Re: Mobile phone gps coordinates
Mar 14, 2020 10:56 AM|NewToDotyNet|LINK
I have built a Web app.
Which uses a browser to view whether on mobile phone or laptop.
I have put this post in Web API, I can not see a section for Web App specifically.
So, I can pass the coordinates from the mobile device to the Web App using the Java example?
All-Star
52971 Points
23571 Posts
Re: Mobile phone gps coordinates
Mar 14, 2020 11:16 AM|mgebhard|LINK
Yes. But the language is JavaScript not Java! JavaScript is used to write code that runs in the browser; a browser application. Please see the following code example whihc I copied from the link in my first post.
Use AJAX or a standard HTTP GET or POST to send the geo location to Web API. The design depends on how your application works which is unknown at this time.
Member
25 Points
189 Posts
Re: Mobile phone gps coordinates
Mar 14, 2020 11:21 AM|NewToDotyNet|LINK
Yes sorry, JavaScript not Java.
Which line forwards the location to the App?
Just spotted text at bottom to answer this question..
Use AJAX or a standard HTTP GET or POST to send the geo location to Web API. The design depends on how your application works which is unknown at this time.
Thanks,
Contributor
3730 Points
1409 Posts
Re: Mobile phone gps coordinates
Mar 17, 2020 07:48 AM|yij sun|LINK
Hi NewToDotyNet,
Accroding to your description,as far as I think,the getCurrentPosition() method is used to return the user's position.
If the getCurrentPosition() method is successful, it returns a coordinates object to the function specified in the success(Position).The success() function outputs the Latitude and Longitude.
Best regards,
Yijing Sun