Click here to Skip to main content
15,903,770 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I have a requirement of showing google map with .net web application, but here we are giving the latitude and longtude values from the database. I googled on this issue, i searched in google developer site and all sites. But i could not found proper result related to my requirement. Please can help me, if anybody have work on this google maps.

Thanks in advance.



Thanks & Regards,
Vinod Bheemisetty
Posted

1 solution

Hi Maria,

I have used Google Map in my asp.net application, so I think the below snippet will definitely helps you out

Script file that is used to find the location is
JavaScript
<script src="http://maps.google.com/maps?file=api&v=2&key=AIzaSyDBO2QQj003uS59ixG2h5QBHmIv7BTBU4Y&sensor=false">
       type="text/javascript"></script>
   <script type="text/javascript">
       var map;
       var geocoder;
       var address;

       $(document).ready(function () {
           initialize();
       });

       function initialize() {
           if (GBrowserIsCompatible()) {  // does browser support  Google Maps APIMaps API
               map = new GMap2(document.getElementById("map"));
               map.setCenter(new GLatLng(17, 83), 5);
               map.setUIToDefault();
           }
           findAddress();
       }

       function showAddress(addresess) {
           geocoder = new GClientGeocoder();
           // get GLatLng point for the given address
           geocoder.getLatLng(
               address,   // address to look for
               function (point) {  // call back function to process the result
                   if (!point) {  // if address not found
                       alert("Sorry the given address [" + address + "] was not found!");
                   }
                   else {
                       //  point contains the required Latitude and Longitude
                       map.setCenter(point, 15);  // point map to the given
                       var marker = new GMarker(point);
                       map.addOverlay(marker);   // display a marker at the point in the map
                       marker.openInfoWindow(address);  // show address in a window
                   }
               }
           );
       }

       function findAddress() {
           var ddl = document.newGetElementById("ddlLocations");
           address = ddl.options[ddl.selectedIndex].value;  // get selected address from dropdownlist
           showAddress(address);
           return false;   // avoid postback
       }
   </script>

And my view html is
ASP.NET
<asp:dropdownlist id="ddlLocations" runat="server" xmlns:asp="#unknown">
    </asp:dropdownlist>
    <asp:button id="btnGetAddress" runat="server" text="Get Address" onclientclick="return findAddress()" xmlns:asp="#unknown" />
    <p />
    <div id="map" style="width: 800px; height: 600px">
    </div>


As you can the code is self explanatory, just keep it as reference.
Hope this helps you a bit.

Regards,
RK
 
Share this answer
 
v2
Comments
Maria Vinod 28-Nov-13 0:19am    
Thanks a lot RK...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900