Google maps help

.NET programming topics
Post Reply
User avatar
kodi
Corporal
Corporal
Posts: 10
Joined: Fri Jun 10, 2011 4:27 pm

Google maps help

Post by kodi » Sun Oct 09, 2011 6:03 am

I want to use google maps in my site developed using visual studio(.net). I have found the code and learnt how to use it. Now I want to open the map in a new windows when a button is clicked. Since the google maps code is a javascript code I don't know how to use it with a button click (I am new to programming). I also want to pass two parameters from the database to use in coordinates of the map. what is the proper way to do this.
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: Google maps help

Post by Neo » Sun Oct 09, 2011 5:55 pm

Though there are some guys who fetch Google map images from web for offline use, according to my memory it is illegal (Google only allows fetching their maps online). I came across a nice .Net cotrol written for Google Maps in CodeProject. I'm sure it will give you some help. Lat Lays Flat - Part 1 : A Google Maps .NET Control.
User avatar
kodi
Corporal
Corporal
Posts: 10
Joined: Fri Jun 10, 2011 4:27 pm

Re: Google maps help

Post by kodi » Sun Oct 09, 2011 7:08 pm

I'm not using them Offline. I'm using the code given by Google themselves. I just need to know how to open the map in a new window when a button click is performed.
User avatar
Herath
Major
Major
Posts: 417
Joined: Thu Aug 05, 2010 7:09 pm

Re: Google maps help

Post by Herath » Sun Oct 09, 2011 10:26 pm

Looks like you want to open a map in a new window. For this you will have to get familiarized with Google Maps API. It's easy.
Then you will need to add code to open up a new window and pass the coordinates to it as query strings or using any other method. I do not have ASP.NET installed to give it a try. The installer is giving an error. I will check if i could install it.
User avatar
Enigma
Lieutenant
Lieutenant
Posts: 74
Joined: Sun Jan 16, 2011 12:40 am
Location: Colombo, Sri Lanka

Re: Google maps help

Post by Enigma » Tue Oct 11, 2011 3:48 am

Hello
Try this sample. May help you out. Make sure to add your APIKEY to the script which is in the MapWindow.aspx
GoogleMapTest.zip
(132.28 KiB) Downloaded 411 times
Thanks
Last edited by Neo on Tue Oct 11, 2011 10:13 am, edited 1 time in total.
Reason: Attachment added to post
User avatar
kodi
Corporal
Corporal
Posts: 10
Joined: Fri Jun 10, 2011 4:27 pm

Re: Google maps help

Post by kodi » Tue Oct 11, 2011 8:18 am

The code I use don't ask for a API key. This is the code

Code: Select all

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0; padding: 0 }
  #map_canvas { height: 100% }
</style>
<script type="text/javascript"
    src="http://maps.googleapis.com/maps/api/js?sensor=true">
</script>
<script type="text/javascript">
    function initialize() {
       
        var myLat = 6.581481;
        var myLng = 79.96459;
        var latlng = new google.maps.LatLng(myLat,myLng);
        var myOptions = {
            zoom: 17,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP   
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
    }

</script>
</head>
<body onload="initialize()">
  <div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>
Instead of hard coding the coordinates I want to pass them from a database. I can't call this javascript code from a button click in Visual Studio
User avatar
Enigma
Lieutenant
Lieutenant
Posts: 74
Joined: Sun Jan 16, 2011 12:40 am
Location: Colombo, Sri Lanka

Re: Google maps help

Post by Enigma » Tue Oct 11, 2011 12:04 pm

Hi
Made some alterations for the code. Try this.
GoogleMapTest(Edited).zip
(132.93 KiB) Downloaded 401 times
User avatar
Herath
Major
Major
Posts: 417
Joined: Thu Aug 05, 2010 7:09 pm

Re: Google maps help

Post by Herath » Tue Oct 11, 2011 8:05 pm

I also had time to do some modifications. Had little help from http://www.mikeborozdin.com/post/Workin ... SPNET.aspx
GoogleMapTest.rar
(122.12 KiB) Downloaded 412 times
User avatar
kodi
Corporal
Corporal
Posts: 10
Joined: Fri Jun 10, 2011 4:27 pm

Re: Google maps help

Post by kodi » Wed Oct 12, 2011 4:07 am

Thank a ton guys. This is exactly what I wanted :yahoo:
You guys were so helpful. Thanks again.
Post Reply

Return to “.NET Programming”