BlazorGoogleMaps 4.15.1

BlazorGoogleMaps

🗺️ Blazor interop for Google Maps JavaScript API

NuGet version (BlazorGoogleMaps) .NET 10

A powerful and easy-to-use Blazor library for integrating Google Maps into your Blazor WebAssembly and Blazor Server applications.


📑 Table of Contents


✨ Features

  • 🎯 Full Google Maps API Support - Markers, Polylines, Polygons, Circles, Info Windows, and more
  • 🚀 Blazor WebAssembly & Server - Works seamlessly with both hosting models
  • 🎨 Advanced Markers - Render Blazor components directly on the map
  • 📍 Marker Clustering - Built-in support for marker clustering
  • 🔥 Heat Maps - Visualize data density with heat map layers
  • 🛣️ Directions & Routes - Full support for directions and route rendering
  • 🎭 Map Styling - Customize map appearance with style options
  • 📊 Data Layers - Support for GeoJSON and other data formats
  • Event Handling - Comprehensive event support for interactive maps
  • 🎨 Drawing Tools - Built-in drawing manager for shapes and overlays

📋 Prerequisites

  • .NET 8.0 or higher
  • A valid Google Maps API key (Get one here)

📦 Installation

Install the package via NuGet Package Manager:

dotnet add package BlazorGoogleMaps

Or via NuGet Package Manager Console:

Install-Package BlazorGoogleMaps

🚀 Quick Start

Step 1: Configure Your API Key

Add BlazorGoogleMaps to your Program.cs:

builder.Services.AddBlazorGoogleMaps("YOUR_GOOGLE_API_KEY");

Option 2: Advanced Configuration

builder.Services.AddBlazorGoogleMaps(new GoogleMapsComponents.Maps.MapApiLoadOptions("YOUR_GOOGLE_API_KEY")
{
	Version = "beta",
	Libraries = "places,visualization,drawing,marker"
});

Option 3: Custom Key Service

For more complex scenarios (e.g., loading keys asynchronously from a database):

builder.Services.AddScoped<IBlazorGoogleMapsKeyService, YourCustomKeyService>();

⚠️ Legacy Method (Not Recommended): Adding the script tag directly to your HTML is still supported but not recommended.


Step 2: Add JavaScript References

Add the required JavaScript files to your wwwroot/index.html (Blazor WASM) or _Host.cshtml/_HostLayout.cshtml (Blazor Server):

<script src="_content/BlazorGoogleMaps/js/objectManager.js"></script>

Optional: For marker clustering support, add:

<script src="https://unpkg.com/@googlemaps/markerclusterer/dist/index.min.js"></script>

💡 Usage Examples

Basic Map

Create a simple map component:

@page "/map"
@using GoogleMapsComponents
@using GoogleMapsComponents.Maps

<h1>Google Map</h1>
<div style="height: 500px;">
	<GoogleMap @ref="@_map1" 
			   Id="map1" 
			   Options="@_mapOptions" 
			   Height="100%" 
			   OnAfterInit="@AfterMapRender">
	</GoogleMap>
</div>

@code {
	private GoogleMap? _map1;
	private MapOptions _mapOptions = default!;

	protected override void OnInitialized()
	{
		_mapOptions = new MapOptions()
		{
			Zoom = 13,
			Center = new LatLngLiteral()
			{
				Lat = 13.505892,
				Lng = 100.8162
			},
			MapTypeId = MapTypeId.Roadmap
		};
	}

	private async Task AfterMapRender()
	{
		// Map is ready - you can perform additional initialization here
		var bounds = await LatLngBounds.CreateAsync(_map1!.JsRuntime);
	}
}

Advanced Map with Blazor Components

Render interactive Blazor components as markers (requires Google Maps v=beta and a MapId):

@page "/advanced-map"
@using GoogleMapsComponents
@using GoogleMapsComponents.Maps

<h1>Advanced Map with Blazor Markers</h1>
<AdvancedGoogleMap @ref="@_map1" Id="map1" Options="@_mapOptions">
	@foreach (var marker in Markers)
	{
		<MarkerComponent 
			@key="marker.Id" 
			Lat="@marker.Lat" 
			Lng="@marker.Lng" 
			Clickable="@marker.Clickable" 
			Draggable="@marker.Draggable" 
			OnClick="@(() => marker.Active = !marker.Active)"
			OnMove="@(pos => marker.UpdatePosition(pos))">
			<div class="custom-marker">
				<h4>@marker.Title</h4>
				<p>Custom Blazor Content</p>
			</div>
		</MarkerComponent>
	}
</AdvancedGoogleMap>

@code {
	private AdvancedGoogleMap? _map1;
	private List<MarkerData> Markers = 
	[
		new MarkerData { Id = 1, Lat = 13.505892, Lng = 100.8162, Title = "Location 1" }
	];

	private MapOptions _mapOptions = new()
	{
		Zoom = 13,
		Center = new LatLngLiteral()
		{
			Lat = 13.505892,
			Lng = 100.8162
		},
		MapId = "DEMO_MAP_ID", // Required for advanced markers
		MapTypeId = MapTypeId.Roadmap
	};

	public class MarkerData
	{
		public int Id { get; set; }
		public string Title { get; set; } = string.Empty;
		public double Lat { get; set; }
		public double Lng { get; set; }
		public bool Clickable { get; set; } = true;
		public bool Draggable { get; set; }
		public bool Active { get; set; }

		public void UpdatePosition(LatLngLiteral position)
		{
			Lat = position.Lat;
			Lng = position.Lng;
		}
	}
}

🎮 Live Demos

Explore interactive examples and learn more features:

The server-side demos include the most up-to-date examples covering:

  • Markers and Info Windows
  • Polylines, Polygons, and Circles
  • Heat Maps and Data Layers
  • Drawing Manager
  • Routes and Directions
  • Event Handling
  • Map Styling
  • And much more!

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.


📄 License

This project is licensed under the MIT License.


🙏 Acknowledgments

  • Built with ❤️ for the Blazor community
  • Powered by the Google Maps JavaScript API

Happy Mapping! 🗺️

No packages depend on BlazorGoogleMaps.

Version Downloads Last updated
4.15.1 2 3/1/2026
4.15.0 1 2/19/2026
4.14.1 3 1/15/2026
4.14.0 5 11/30/2025
4.13.8 8 11/24/2025
4.13.7 5 11/23/2025
4.13.6 10 8/14/2025
4.13.5 13 8/1/2025
4.13.4 15 8/1/2025
4.13.3 9 8/1/2025
4.13.2 12 7/29/2025
4.13.1 12 8/1/2025
4.13.0 15 6/30/2025
4.12.2 12 6/29/2025
4.12.1 19 6/28/2025
4.12.0 15 6/28/2025
4.11.3 18 6/28/2025
4.11.2 13 6/29/2025
4.11.1 14 6/29/2025
4.11.0 17 6/28/2025
4.10.1 11 6/29/2025
4.10.0 12 6/29/2025
4.9.5 16 6/28/2025
4.9.4 12 6/28/2025
4.9.3 11 3/7/2025
4.9.2 17 3/7/2025
4.9.1 14 3/7/2025
4.9.0 14 3/7/2025
4.8.0 17 3/7/2025
4.7.15 12 3/7/2025
4.7.14 12 3/7/2025
4.7.13 13 3/7/2025
4.7.12 15 3/7/2025
4.7.11 13 3/7/2025
4.7.10 13 3/7/2025
4.7.9 16 3/7/2025
4.7.8 16 3/7/2025
4.7.7 16 3/7/2025
4.7.6 14 3/7/2025
4.7.5 12 3/7/2025
4.7.4 12 3/7/2025
4.7.3 13 3/7/2025
4.7.2 17 3/7/2025
4.7.1 15 3/7/2025
4.7.0 14 3/7/2025
4.6.2 15 3/7/2025
4.6.1 13 3/7/2025
4.6.0 11 3/7/2025
4.5.0 14 3/7/2025
4.4.2 14 3/7/2025
4.4.1 15 3/7/2025
4.4.0 13 3/7/2025
4.3.0 11 3/7/2025
4.2.0 12 3/7/2025
4.1.2 16 3/7/2025
4.1.1 16 3/7/2025
4.1.0 12 3/7/2025
4.0.3 15 3/7/2025
4.0.2 14 3/7/2025
4.0.1 14 3/7/2025
4.0.0 15 3/7/2025
3.3.2 11 3/7/2025
3.3.1 16 3/7/2025
3.2.5 16 3/7/2025
3.2.4 14 3/7/2025
3.2.3 13 3/7/2025
3.2.2 16 3/7/2025
3.2.1 14 3/7/2025
3.2.0 12 3/7/2025
3.1.4 15 3/7/2025
3.1.3 11 3/7/2025
3.1.2 17 3/7/2025
3.1.1 13 3/7/2025
3.1.0 17 3/7/2025
3.0.8 15 3/7/2025
3.0.7 14 3/7/2025
3.0.6 13 3/7/2025
3.0.5 16 3/7/2025
3.0.4 15 3/7/2025
3.0.3 22 3/7/2025
3.0.2 17 3/7/2025
3.0.1 11 3/7/2025
3.0.0 14 3/7/2025
2.5.7 17 3/7/2025
2.5.6 12 3/7/2025
2.5.5 10 3/7/2025
2.5.4 15 3/7/2025
2.5.3 14 3/7/2025
2.5.2 19 6/25/2023
2.5.1 11 3/7/2025
2.4.4 14 3/7/2025
2.4.3 10 3/7/2025
2.4.2 14 3/7/2025
2.4.1 11 3/7/2025
2.3.1 19 3/7/2025
2.2.6 11 3/7/2025
2.2.5 12 3/7/2025
2.2.4 15 3/7/2025
2.2.3 16 3/7/2025
2.2.2 13 3/7/2025
2.2.1 13 3/7/2025
2.2.0 13 3/7/2025
2.1.1 15 3/7/2025
2.1.0 13 3/7/2025
2.0.6 16 3/7/2025
2.0.5 13 3/7/2025
2.0.4 14 3/7/2025
2.0.3 12 3/7/2025
2.0.2 16 3/7/2025
2.0.1 16 3/7/2025
2.0.0 19 3/7/2025
1.5.5 22 3/7/2025
1.5.4 14 3/7/2025
1.5.3 11 10/30/2023
1.5.2 10 3/7/2025
1.5.1 14 3/7/2025
1.4.2 13 3/7/2025
1.4.1 16 3/7/2025
1.4.0 14 3/7/2025
1.3.0 10 3/7/2025
1.2.1 17 3/7/2025
1.1.8 17 10/19/2023
1.1.7 12 3/7/2025
1.1.6 16 3/7/2025
1.1.5 14 3/7/2025
1.1.4 12 3/7/2025
1.1.3 14 10/21/2023
1.1.2 14 3/7/2025
1.1.1 15 3/7/2025
1.0.17 13 3/7/2025
1.0.16 13 3/7/2025
1.0.15 20 3/7/2025
1.0.14 15 3/7/2025
1.0.13 16 3/7/2025
1.0.12 14 3/7/2025
1.0.11 22 3/7/2025
1.0.10 13 3/7/2025
1.0.9 16 3/7/2025
1.0.8 13 3/7/2025
1.0.7 13 3/7/2025
1.0.6 17 3/7/2025
1.0.5 14 3/7/2025
1.0.4 12 3/7/2025
1.0.3 15 3/7/2025
1.0.2 14 3/7/2025
1.0.1 16 3/7/2025
1.0.0 13 3/7/2025
0.9.3 12 3/7/2025
0.9.2 17 3/7/2025
0.9.1 14 3/7/2025
0.9.0 15 10/28/2023
0.8.1 12 3/7/2025
0.8.0 14 3/7/2025
0.7.1 14 3/7/2025
0.6.14 8 3/7/2025
0.6.13 12 3/7/2025
0.6.12 13 3/7/2025
0.6.11 14 11/10/2023
0.6.10 14 3/7/2025
0.6.9 14 3/7/2025
0.6.8 11 3/7/2025
0.6.7 11 3/7/2025
0.6.6 13 11/3/2023
0.6.5 12 3/7/2025
0.6.4 14 3/7/2025
0.6.3 14 3/7/2025
0.6.2 12 3/7/2025
0.6.1 15 3/7/2025
0.6.0 12 3/7/2025
0.5.9 16 3/7/2025
0.5.8 15 3/7/2025
0.5.7 13 3/7/2025
0.5.6 14 3/7/2025
0.5.5 14 3/7/2025
0.5.4 14 3/7/2025
0.5.3 13 3/7/2025
0.5.2 13 3/7/2025
0.5.1-alpha 12 3/7/2025
0.4.8-alpha 18 3/7/2025
0.4.7-alpha 12 3/7/2025
0.4.6-alpha 15 3/7/2025
0.4.5-alpha 14 3/7/2025
0.4.0-alpha 15 3/7/2025
0.3.0 14 10/26/2023
0.1.0 18 3/7/2025