[Webinar] Streamline your web hosting managementRegister Today


google maps multiple points marker

Posted on 2010-03-31
Medium Priority
Last Modified: 2013-11-27
Hi all;

How to view messages for each point separately.
points comes from the database dynamically (multiple points)

My code (vb.net code behind)

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
                Dim myGoogleMap As New StringBuilder
                myGoogleMap.Append("<script src='http://maps.google.com/maps?file=api&v=2&key=**************'" + vbCrLf)
                myGoogleMap.Append("type='text/javascript'></script>" + vbCrLf)
                myGoogleMap.Append("<script type='text/javascript'>" + vbCrLf)
                myGoogleMap.Append(vbCrLf + vbCrLf)
                myGoogleMap.Append("var map = null;" + vbCrLf)
                myGoogleMap.Append("var mapObj = null;" + vbCrLf)
                myGoogleMap.Append("var geoCoder = null;" + vbCrLf)
                myGoogleMap.Append(vbCrLf + vbCrLf)
                myGoogleMap.Append("mapObj = document.getElementById('map');" + vbCrLf)
                myGoogleMap.Append("map = new GMap2(mapObj);" + vbCrLf)
                myGoogleMap.Append("geocoder = new GClientGeocoder();" + vbCrLf)
                myGoogleMap.Append("map.setCenter(new GLatLng(39.9725,32.8636), + 6);" + vbCrLf)
                'myGoogleMap.Append("map.setCenter(new GLatLng(" + coordinate + "), + 5);" + vbCrLf)

                Dim dv As DataView = CType(sqlTesisler.Select(DataSourceSelectArguments.Empty), DataView)
                Dim latitude As String = ""
                Dim Longitude As String = ""
                Dim place As String = ""
                Dim coordinate As String = ""

                For i = 0 To dv.Table.Rows.Count - 1
                    latitude = dv.Table.Rows(i).Item("latitude").ToString()
                    Longitude = dv.Table.Rows(i).Item("Longitude").ToString()
                    place = dv.Table.Rows(i).Item("Adi").ToString()
                    coordinate = Replace(latitude, ",", ".") & "," & Replace(Longitude, ",", ".")

                    myGoogleMap.Append("var point = new GLatLng(" + coordinate + ");" + vbCrLf)
                    myGoogleMap.Append("map.addOverlay(new GMarker(point));" + vbCrLf)
                   'point message

                myGoogleMap.Append("map.addControl(new GSmallMapControl());" + vbCrLf)
                myGoogleMap.Append("map.addControl(new GMapTypeControl());" + vbCrLf)
                myGoogleMap.Append("GMap2.prototype.wheelZoom = function(event)" + vbCrLf)
                myGoogleMap.Append("{ if((event.detail || -event.wheelDelta) < 0)" + vbCrLf)
                myGoogleMap.Append("  { map.zoomIn();} else { map.zoomOut();}" + vbCrLf)
                myGoogleMap.Append("return false; " + vbCrLf)
                myGoogleMap.Append("} " + vbCrLf)

                myGoogleMap.Append("GEvent.addDomListener(mapObj, 'DOMMouseScroll', map.wheelZoom); " + vbCrLf)
                myGoogleMap.Append("GEvent.addDomListener(mapObj, 'mousewheel', map.wheelZoom);" + vbCrLf)
                myGoogleMap.Append("GEvent.addListener(map, 'click', function(marker, point) { map.setCenter(point); } ); " + vbCrLf + vbCrLf)

                myGoogleMap.Append("function showAddress(address) {" + vbCrLf)
                myGoogleMap.Append("  ;" + vbCrLf)
                myGoogleMap.Append("  alert ('In function')" + vbCrLf)
                myGoogleMap.Append("  geocoder.getLatLng(" + vbCrLf)
                myGoogleMap.Append("    address," + vbCrLf)
                myGoogleMap.Append("    function(point) {" + vbCrLf)
                myGoogleMap.Append("      if (!point) {" + vbCrLf)
                myGoogleMap.Append("        alert(address + ' not found');" + vbCrLf)
                myGoogleMap.Append("      } else {" + vbCrLf)
                myGoogleMap.Append("       map.setCenter(point, 13);" + vbCrLf)
                myGoogleMap.Append("        var marker = new GMarker(point);" + vbCrLf)
                myGoogleMap.Append("        map.addOverlay(marker);" + vbCrLf)
                myGoogleMap.Append("        marker.openInfoWindowHtml(address);" + vbCrLf)
                myGoogleMap.Append("      }" + vbCrLf)
                myGoogleMap.Append("    }" + vbCrLf)
                myGoogleMap.Append("  );" + vbCrLf)
                myGoogleMap.Append("}" + vbCrLf)


                If (Not Me.ClientScript.IsStartupScriptRegistered("StartMap")) Then
                    Me.ClientScript.RegisterStartupScript(GetType(String), "StartMap", myGoogleMap.ToString())
                End If
            Catch ex As Exception
                txtDurum.Text = "Error : " & ex.Message
            End Try

        End If
    End Sub
Question by:dmiebim
  • 2
  • 2

Expert Comment

ID: 29213430
Ok, I know my code is not .NET, it's classic asp but maybe it will help you get an idea.
My var "ps" defines all my locations in lat and long looping through my database and puts it in an array. When it finishes it goes back to the beginning of the recordset.
Afterwhich, the var "ls" starts a new array that contains my messages after clicked code.
The part that throws it all together is where you can see the ps and ls vars:
   for (var i = 0; i < <%=Counter%>; i++) {
     mrks[i] = createMarker(ps[i], ls[i], is[i]);
 The <%=Counter%> is what I used to make sure everything matched up when combining everything together. It may not have been the most efficient way to do it but with limited examples out there this is what works for me, besides I only had 15 locations to map.
Good luck and hope this gets your brain flowing.

		if (GBrowserIsCompatible()) {
			var i1 = new GIcon();
			i1.image = "images/gmarker.png";
			i1.iconSize = new GSize(20, 34);
			i1.iconAnchor = new GPoint(10, 34);
			// i1.shadow = "http://maps.yourgmap.com/m/s0.png";
			// i1.shadowSize = new GSize(1, 1);
			i1.infoWindowAnchor = new GPoint(10, 1);
			var map = new GMap2(document.getElementById("mymap"));
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
			<% if strLocation <> "" then %>
				map.setCenter(new GLatLng(<%=rs.fields("Lat")%>,<%=rs.fields("Long")%>), 17,G_HYBRID_MAP);
			<% else %>
				map.setCenter(new GLatLng(31.8341075,-81.55426025), 12, G_HYBRID_MAP);
			<% end if %>
			var marker = 0;
			var mrks = new Array(<%=Counter%>);
			var ps = new Array(
			<% do while not rs.eof %>
			 		new GLatLng(<%=rs.fields("Lat")%>,<%=rs.fields("Long")%>)<%rs.movenext%><%if rs.eof <> "True" then%>,
				end if
			var ls = new Array(
			<%	Counter = 0				
				do while not rs.eof %>
				'<table><tr><td align="left"><strong><%=rs.fields("Location")%></strong><br /><%=rs.fields("Street")%><br /><%=rs.fields("City_State")%><%=rs.fields("Zip")%><br /><%=rs.fields("PhoneNumber")%><br /><%if rs.fields("Image") <> "" then %><br /><%end if%><br /><a href="<%=rs.fields("Website")%>" target="_top">View Website</a><br/>  <!--- <a href="">Take Virtual Tour</a><br/> -->  <a href="javascript:enableDirections(document.Loc<%=Counter%>.Lo<%=Counter%>.value,<%=rs.fields("Lat")%>,<%=rs.fields("Long")%>,<%=Counter%>)" target="_top">Get Directions to here</a></td><%if rs.fields("Image") <> "" then %><td><a href="<%=rs.fields("Website")%>" target="_top"><img src="<%=rs.fields("Image")%>"></a></td><%end if%></tr></table>'<%rs.movenext%><%if rs.eof <> "True" then%>,
				end if
				Counter = Counter + 1
			var is = new Array(
			<% do while not rs.eof %>i1<%rs.movenext%><%if rs.eof <> "True" then%>,
				end if

			for (var i = 0; i < <%=Counter%>; i++) {
			  mrks[i] = createMarker(ps[i], ls[i], is[i]);
			<% if strLocation <> "" then			' Means that there was user interaction from another page and a school was choosen %>
			<% end if %>

Open in new window


Author Comment

ID: 29238241

I tried but could not convert the code. (vb.net)
points appear. When I click the balloon message does not appear


Accepted Solution

mmarx82 earned 750 total points
ID: 30621168
you should probably do a Request Attention on this or close it altogether.

Author Closing Comment

ID: 32695367
The offered solutions does not solve the problem

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question