Capture which marker the end-user clicked and react to the clicked event..

Add any number of map-markers to your Google map C# or VB webproject from codebehind. Capture which marker the end-user clicked and react to the clicked event..

C# codebehind example code.

using System;
using GoogleMaps.Markers;
namespace GoogleMaps.Samples.Markers
{
public partial class CodeBehind : System.Web.UI.Page
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
GoogleMarkers markers = new GoogleMarkers();
markers.Markers.Add(new Marker
{
Position = new LatLng(42.1229, 24.7879),
Title = ”Click on me”,
Info = ”Text info on marker 1”
});
markers.Markers.Add(new Marker
{
Position = new LatLng(42.7, 23.3),
Title = ”Click on me”,
Info = ”Text info on marker 2”
});
markers.MarkerOptions.Clickable = true;
markers.MarkerOptions.Draggable = true;
markers.Click += HandleClick;
GoogleMap1.Markers.Add(markers);
}
protected void HandleClick(object sender, MarkerEventArgs e)
{
int? index = e.Index;
// this is the position od the clicked marker.
LatLng position = e.Position;
if(index.HasValue)
{
var markers = (GoogleMarkers)sender;
var marker = markers.Markers[index.Value];
// This now should be the clicked marker with all its data.
}
}
}
}


ASPX webpage syntax for the example

<%@ Page Title="" Language="C#" MasterPageFile="Markers.master" AutoEventWireup="false" CodeBehind="CodeBehind.aspx.cs" Inherits="GoogleMaps.Samples.Markers.CodeBehind" %>

Markers Code Behind

GoogleMap control markers code behind sample.