Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am using asp.net with C#. I embedded Google Maps in my application using JavaScript. I input latitude and longitude, and its shows the location on Google Maps. Now I want that it takes lat & lng from a database and shows the location.

Here's my code:

  <script type="text/javascript"
    src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC6v5-2uaq_wusHDktM9ILcqIrlPtnZgEk&sensor=false">
    </script>
    <script type="text/javascript">
        function initialize() {
            var lat = document.getElementById('txtlat').value;
            var lon = document.getElementById('txtlon').value;
            var myLatlng = new google.maps.LatLng(lat, lon) 
            var mapOptions = {
                center: myLatlng,
                zoom: 18,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                marker: true
            };
            var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
            var marker = new google.maps.Marker({
                position: myLatlng
            });
            marker.setMap(map);
        }


    </script>
    </head>

    <body >

    <table>
    <tr>
    <td class="style3">Enter Latitude:</td>
    <td><input type="text" id="txtlat" value="" onclick="return txtlat_onclick()" /> </td>
    </tr>
    <tr>
    <td class="style3">Enter Longitude:</td>
    <td><input type="text" id="txtlon" value="" onclick="return txtlon_onclick()" /> </td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><input type="button" value="Submit" onclick="javascript:initialize()" /> </td>
    </tr>
    </table>
    <div id="map_canvas" style="width: 535px; height: 347px"></div>


    </body>
    </html>
share|improve this question
1  
Is there any specific issue you are facing in it? –  palaѕн May 3 '13 at 16:51
1  
stackoverflow is not a place to ask people to write code for you. –  Win May 3 '13 at 17:10
1  
Where is your data access code? Perhaps we could help if you showed us what you got so far. –  Roberto Hernandez May 3 '13 at 17:45
add comment

1 Answer

Do an ajax request to the server, the server will connect to the database, read the lat and longitude from a table and return. On your ajax handler, replace your lat and lon variables with the response.

Checkout this question: jQuery ajax call to REST service for an idea of how the javascript should look.

Checkout this article on how to build a restful api in c# http://code.msdn.microsoft.com/Build-truly-RESTful-API-194a6253.

Checkout this article on how to connect to a database with c# http://www.daniweb.com/software-development/csharp/threads/21636/how-do-you-connect-to-a-sql-database-using-c

share|improve this answer
 
thnks bro, can u plz put some code –  user2347571 May 3 '13 at 17:18
 
more replies plzz –  user2347571 May 3 '13 at 18:05
2  
@user2347571 You've been given some good suggestions and useful links, and there are already many questions on this site about using JavaScript with SQL Server. I suggest that you try implementing something yourself and if you have specific problems then feel free to post them as questions. –  Pondlife May 3 '13 at 20:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.