Check browser geo location capability and get Latitude and Longtitude

I am developing .net MVC application.

I want to get Geo Location from if it is support html 5.0 browser.

But I want to know can I do it inside a Controller (HomeController, inside index method)

Need your suggestions

Thank You Yohan

Answers


If you add a reference to jQuery in your project, you should then be able to add the following Javascript code to your view. This will then post to your controller with the long and lat. That is the only way you will be able to get the GeoLocation in your controller.

NOTE: This code hasn't been tested! I just wrote it quickly from memory.

// Get the coordinates
navigator.geolocation.getCurrentPosition(show_map);

function show_map(position) {
  var latitude = position.coords.latitude;
  var longitude = position.coords.longitude;

  // post to your controller
  var url = "/Home/Index?latitude=" + latitude + "&longtitude=" + longitude; 
  $.post(url, function(data) {
  });
}

You will also need to add the parameters "latitude" and "longtitude" to your controller.

  public ActionResult Index(string latitude, string longtitude)
  {

  }

Need Your Help

How to return name,value pair via Java Map in Hibernate (using mapping file)

hibernate hibernate-mapping

I am trying to create a name,value pair in Hibernate which gets returned as a Java Map. But I am only getting 1 of the rows returned in the Map. I haven't found any really clear examples of a sim...

How can I represent a Hierarchy of Objects in an XML Schema in a way that is suitable for JAXB and Java

java jaxb xsd object-graph

I have a data model that represents a taxonomy. The taxonomy is a hierarchy of categories, such as

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.