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&v=2&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 ThenWhile 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")) ThenstrLon = drResult("lon").ToString
End If
If Not IsDBNull(drResult("lat")) ThenstrLat = 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 WhileEnd 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 TryReturn strmap
End Function
Please free to ask your queries and if this code is useful for you, kindly post response.
thank you.