Asp.net web application with Google Map results

Karimullah21 1 Reputation point
2021-12-07T02:18:09.67+00:00

Hi Friends,

I have one doubt regarding one application, Pls help.

I want to get the Names of Candidates from the database who is residing 5kms from the radius of the area which I enter into the search box.

I will enter AREA name in search box, It should return names of the candidates who are residing in 5kms radius of the entered area.

How Can I do it. Pls help. Shall I integrate google maps. Pls guide me step by step.

Thanks in Advance.

Regards,

Karim

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,352 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,248 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,217 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 25,471 Reputation points Microsoft Vendor
    2021-12-07T07:52:53.023+00:00

    Hi @Karimullah21 ,
    I think you can do this:
    1.To implement Google Maps, you need to add the following link in the Head section.

    <sc ript type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></s cript>  
    

    2.Get the coordinates of the area in the input box

    var geocoder = new google.maps.Geocoder();  
    var con = document.getElementById('txtCon').value;  
    var city = document.getElementById('txtCity').value;  
    var res = document.getElementById('lblresult');  
    var com = city + "," + con;  
    geocoder.geocode({ 'address': com }, function (results, status) {  
                      if (status == google.maps.GeocoderStatus.OK) {  
                          res.innerHTML = "Latitude : " + results[0].geometry.location.lat() + "<br/>Longitude :" +  
                              results[0].geometry.location.lng();  
                      } else {  
                          res.innerHTML = "Wrong Details: " + status;  
                      }  
    

    3.Obtain the coordinates of the candidate's place of residence in the database
    4.Calculate the distance between two coordinates and return the name if it is greater than 5 kilometers
    var center = new google.maps.LatLng(3.2987599, 102.6872022);
    var latLng = new google.maps.LatLng(3.0987599, 101.6872022);
    var distanceInMetres = google.maps.geometry.spherical.computeDistanceBetween(center, latLng);
    Distance between 2 points: (lat1,lon1) to (lat2,lon2)

    distance = acos(  
         cos(lat1 * (PI()/180)) *  
         cos(lon1 * (PI()/180)) *  
         cos(lat2 * (PI()/180)) *  
         cos(lon2 * (PI()/180))  
         +  
         cos(lat1 * (PI()/180)) *  
         sin(lon1 * (PI()/180)) *  
         cos(lat2 * (PI()/180)) *  
         sin(lon2 * (PI()/180))  
         +  
         sin(lat1 * (PI()/180)) *  
         sin(lat2 * (PI()/180))  
        ) * 3959  
    

    3959 is the Earth radius in Miles. Replace this value with radius in KM, (or any other unit), to get results on the same unit.

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments