Google Maps via ASP.NET / SQL Server Tutorial

Last post 10-30-2009 11:03 AM by ice_boy-20. 17 replies.

Sort Posts:

  • Google Maps via ASP.NET / SQL Server Tutorial

    07-08-2008, 6:53 AM

    Hi,

          I worked out for google map with ASP.Net / VB.Net. below steps you have to follow,

             1. You need to get encrpyted key from google which key for your own website.

             2. create a table as below,

              if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[map]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
                drop table [dbo].[map]
              GO

               CREATE TABLE [dbo].[map] (
                [id] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
               [lat] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
               [lon] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
              [description] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
              [cid] [numeric](18, 0) NOT NULL ---cid meant centerID
             ) ON [PRIMARY]
            GO

          3. Copy below code for map_test.aspx page

                   <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Map_test.aspx.vb" Inherits="Map_test" %>

                   <% Response.Write(maptest())%>

          4. Below code for map_test.aspx.vb

               

    Public Function maptest() As String

    Dim strmap As String = ""

    ' Dim strMap As String = ""

    Dim strMap1 As String = ""

    Dim drResult As SqlDataReader

    Dim SQLResult As String = ""

    Dim strLon As String = ""

    Dim strLat As String = ""

    Try

    strmap = strmap + " <!DOCTYPE html PUBLIC """"-//W3C//DTD XHTML 1.0 Strict//EN"""" """"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">"

    strmap = strmap + " <html xmlns=""http://www.w3.org/1999/xhtml"">"

    strmap = strmap + " <head>"

    strmap = strmap + " <meta http-equiv=""content-type"" content=""google maps via ASP.Net : text/html; charset=utf-8""/>"

    strmap = strmap + " <title>Google Maps JavaScript API Example</title>"

    strmap = strmap + " <script src=""http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAXu6-xqCzQg7UF16n1xbPlxRy0V4Q1dfyNo3tEYtAttAGexdRsBSFtycVVZx_tF4NT4Xrn_SOyBa6pQ"""

    strmap = strmap + " type=""text/javascript""></script>"

    strmap = strmap + " <script type=""text/javascript"">"

    'strmap = strmap + " //<![CDATA["

    'strmap = strmap + " // Creates a marker whose info window displays the given number"

    strmap = strmap + " function createMarker(point, number)"

    strmap = strmap + " {"

    strmap = strmap + " var marker = new GMarker(point);"

    'strmap = strmap + " // Show this markers index in the info window when it is clicked"

    strmap = strmap + " var html = number;"

    strmap = strmap + " GEvent.addListener(marker, ""click"", function() {marker.openInfoWindowHtml(html);});"

    strmap = strmap + " return marker;"

    strmap = strmap + " };"

    strmap = strmap + " function load() {"

    strmap = strmap + " if (GBrowserIsCompatible()) {"

    strmap = strmap + " var map = new GMap2(document.getElementById(""map""));"

    strmap = strmap + " map.addControl(new GLargeMapControl());"

    strmap = strmap + " map.addControl(new GMapTypeControl());"

    strmap = strmap + " map.addControl(new GScaleControl());"

    Dim blnPoint As Boolean = False

    clsSearch.ConnectionString() ' calling connectionstring function

    SQLResult = "Select * from map where cid=12"  ' i just hard code for center id.

    drResult = SqlHelper.ExecuteReader(clsSearch.t_IncidentStr, CommandType.Text, SQLResult) ' executing sql query by using sql helper class

    If drResult.HasRows Then

    While drResult.Read

    If blnPoint = False Then

    strmap = strmap + " map.setCenter(new GLatLng(" & drResult("lat").ToString & "," & drResult("lon").ToString & "), 13);"

    blnPoint = True

    End If

    If Not IsDBNull(drResult("lon")) Then

    strLon = drResult("lon").ToString

    End If

    If Not IsDBNull(drResult("lat")) Then

    strLat = drResult("lat").ToString

    End If

    strmap = strmap + "var point = new GLatLng(" & drResult("lat").ToString & "," & drResult("lon").ToString & ");"

    strmap = strmap + " var marker = createMarker(point,'" & drResult("lat").ToString & "');"

    strmap = strmap + "map.addOverlay(marker);"

    End While

    End If

     

     

    strmap = strmap + " }"

    strmap = strmap + " }"

    ' strmap = strmap + " //]]>"

    strmap = strmap + " </script>"

    strmap = strmap + " </head>"

    strmap = strmap + " <body onload=""load()"" onunload=""GUnload()"">"

    strmap = strmap + " <div id=""map"" style=""width: 1200px; height: 600px""></div>"

    strmap = strmap + " </body>"

    strmap = strmap + " </html>"

    Catch ex As Exception

    End Try

    Return strmap

    End Function

    Please free to ask your queries and if this code is useful for you, kindly post response.

     thank you.


     

     

  • Re: Google Maps via ASP.NET / SQL Server Tutorial

    07-08-2008, 7:34 AM
    • Member
      258 point Member
    • prah.NET
    • Member since 11-23-2007, 4:53 PM
    • Delhi
    • Posts 59

    hi

    i think you should write it as an article or blog...

    in that way more people could get advantage of your work

    thanks and regards

    prahlad

    Prahlad Kumar Sharma
  • Re: Google Maps via ASP.NET / SQL Server Tutorial

    07-08-2008, 12:54 PM

    Hi,

         Thanks for suggestion.

    Regards,

    Vijayan.

  • Re: Google Maps via ASP.NET / SQL Server Tutorial

    07-23-2008, 9:02 AM

     Hi vijayan

     

    Tell me how to get Encrypted key for our website from google.....

     

    And describe the what the Map table contains and their colums..I am unable to know about that 

    Thanks In Adv :)

  • Re: Google Maps via ASP.NET / SQL Server Tutorial

    07-24-2008, 7:23 AM
    Answer

    You can get the encrypted key from http://www.google.com/local/add/lookup?hl=en-US&gl=US

    you will get unique key for the google map.

    the table which i given the post is enough for the map. just copy and paste to create the table.

    if it is useful information , pls mark it as ANSWER.

     thanks.

  • Re: Google Maps via ASP.NET / SQL Server Tutorial

    07-24-2008, 7:40 AM

    My queries 

     

    How to fill that Table?? 

    What does lat,lon,Cid Stands for ??

    Always DataReader gives empty because there are no rows in Table 

    How to give a particular locations to find ?? like giving input 

    I ran your code but  i got blank map image with out location :( and some java script error when we are  dragging

    Please help me in this issue 

  • Re: Google Maps via ASP.NET / SQL Server Tutorial

    07-25-2008, 2:09 AM
    Answer

    How to fill that Table?? 

    get the location's longitude and latitude for your place(where you want to point it out n the map) from web

    What does lat,lon,Cid Stands for ??

       CID which is primary key( not neccessary, it depends on ur requirements)

       lat - latitude ( which latitude for your place)

       lon- longitude

    Always DataReader gives empty because there are no rows in Table 

    Please post ur code

    How to give a particular locations to find ?? like giving input 

    find the longitude and latitude of the locations from the web ( example : http://jan.ucc.nau.edu/~cvm/latlon_find_location.html )

     Good Luck.

     

  • Re: Google Maps via ASP.NET / SQL Server Tutorial

    07-25-2008, 2:32 AM

     Hi

    Vijayan

    Thanks a lot for ur  help

    I jst copied ur code. but its giving one error " We are sorry ,But we dont have maps at this zoom level .Please look broader level"

     How to give zoom level ?? Where are giving that in your code??

    I instered in Map Table as for ex Hongkong city  lat  as  22 15 N  lat as 114 10 E .. is this fine or any changes??

    Thanks  

     

     

     

     

     

     

  • Re: Google Maps via ASP.NET / SQL Server Tutorial

    07-25-2008, 3:12 AM

    You must use 22 15N  as 22.15 in the coordinates n the table.

    mail me antonyvijayan@gmail.com or i m online.

     Gud luck

  • Re: Google Maps via ASP.NET / SQL Server Tutorial

    09-10-2008, 2:53 AM
    • All-Star
      21,630 point All-Star
    • venkatu2005
    • Member since 07-01-2008, 10:48 AM
    • Posts 4,679

    Hai

    I got error on

    clsSearch , CommandType not declared

    let me know...

    actually wat it shows..

    wat is the use of creating table .

    how you store the data...

    let me know in detail... 

     

     

    I have Changed My Blog from (http://venkat-dotnetsamples.blogspot.com) to (http://venkat-dotnetsnippets.blogspot.com)

    Regards,
    Venkatesan.M

    Please Mark as Answered If its helpful and Un-Mark as Answered if it not help u.
  • Re: Google Maps via ASP.NET / SQL Server Tutorial

    09-10-2008, 3:15 AM

    Hi,

       You might not defined the command type. The table data will be shown dynamic marks on the places where the latitude and longitude measurements from the tables. So that using the tables. To store the data, you might directly enter the data into the table or you shld hve page to add it into table.

    Good Luck.

  • Re: Google Maps via ASP.NET / SQL Server Tutorial

    09-10-2008, 3:21 AM
    • All-Star
      21,630 point All-Star
    • venkatu2005
    • Member since 07-01-2008, 10:48 AM
    • Posts 4,679

     Hai

    I have place your code as its

    It show the SqlHelper , ClsSearch, Command type not declared

    Let you give the full code.. 

    or wat Changes shall i make... 

    I have Changed My Blog from (http://venkat-dotnetsamples.blogspot.com) to (http://venkat-dotnetsnippets.blogspot.com)

    Regards,
    Venkatesan.M

    Please Mark as Answered If its helpful and Un-Mark as Answered if it not help u.
  • Re: Google Maps via ASP.NET / SQL Server Tutorial

    09-10-2008, 3:38 AM

    please change this line drResult = SqlHelper.ExecuteReader(clsSearch.t_IncidentStr, CommandType.Text, SQLResult)

    as

      Dim dsResult as Dataset

      Dim cmdResult as new command

      Dim daSqladapter as new sqldataadapter

     

      cmdresutl.commandtype=

      cmdResult.connection=<connection>

      daSqladapter.selectcommand= cmdResult

       dasqladapter.fill(dsresult)

     

    clsSearch.t_IncidentStr is connection string

    above code flow is incorrect. just for sample i gave you. Order the code correctly.let me know if u hve further queries.

     

  • Re: Google Maps via ASP.NET / SQL Server Tutorial

    09-10-2008, 3:45 AM
    • All-Star
      21,630 point All-Star
    • venkatu2005
    • Member since 07-01-2008, 10:48 AM
    • Posts 4,679

     Hai

    If u have full code Let u paste here.. 

    I have Changed My Blog from (http://venkat-dotnetsamples.blogspot.com) to (http://venkat-dotnetsnippets.blogspot.com)

    Regards,
    Venkatesan.M

    Please Mark as Answered If its helpful and Un-Mark as Answered if it not help u.
  • Re: Google Maps via ASP.NET / SQL Server Tutorial

    09-10-2008, 3:46 AM
    • All-Star
      21,630 point All-Star
    • venkatu2005
    • Member since 07-01-2008, 10:48 AM
    • Posts 4,679

     Hai

    If u have full code Let u paste here.. 

    I have Changed My Blog from (http://venkat-dotnetsamples.blogspot.com) to (http://venkat-dotnetsnippets.blogspot.com)

    Regards,
    Venkatesan.M

    Please Mark as Answered If its helpful and Un-Mark as Answered if it not help u.
Page 1 of 2 (18 items) 1 2 Next >