BlazorGoogleMaps 4.11.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package BlazorGoogleMaps --version 4.11.3
                    
NuGet\Install-Package BlazorGoogleMaps -Version 4.11.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BlazorGoogleMaps" Version="4.11.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BlazorGoogleMaps" Version="4.11.3" />
                    
Directory.Packages.props
<PackageReference Include="BlazorGoogleMaps" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BlazorGoogleMaps --version 4.11.3
                    
#r "nuget: BlazorGoogleMaps, 4.11.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=BlazorGoogleMaps&version=4.11.3
                    
Install BlazorGoogleMaps as a Cake Addin
#tool nuget:?package=BlazorGoogleMaps&version=4.11.3
                    
Install BlazorGoogleMaps as a Cake Tool

BlazorGoogleMaps

Blazor interop for GoogleMap library

NuGet version (BlazorGoogleMaps)

Usage

  1. Provide your Google API key to BlazorGoogleMaps with one of the following methods. (You can get a key here: https://developers.google.com/maps/documentation/javascript/get-api-key)

Use the bootstrap loader with a key service (recommended):

services.AddBlazorGoogleMaps("YOUR_KEY_GOES_HERE");

OR specify google api libraries and/or version:

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

OR to do something more complex (e.g. looking up keys asynchronously), implement a Scoped key service and add it with something like:

services.AddScoped<IBlazorGoogleMapsKeyService, YourServiceImplementation>();

OR (legacy - not recommended) Add google map script HEAD tag to wwwroot/index.html in Client side or _Host.cshtml in Server Side.

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=YOUR_KEY_GOES_HERE&v=3"></script>
  1. Add path to project javascript functions file in wwwroot/index.html for Blazor WASM, or in _Host.cshtml or _HostLayout.cshtml for Blazor Server.
<script src="_content/BlazorGoogleMaps/js/objectManager.js"></script>

If you want to use marker clustering add this script as well:

<script src="https://unpkg.com/@googlemaps/markerclusterer/dist/index.min.js"></script>
  1. Using the component is the same for both Blazor WASM and Blazor Server
@page "/map"
@using GoogleMapsComponents
@using GoogleMapsComponents.Maps

<h1>Google Map</h1>
<div style="height:@Height">
<GoogleMap @ref="@_map1" Id="map1" Options="@mapOptions" Height="100%" OnAfterInit="AfterMapRender"></GoogleMap>
</div>
@functions {
	private GoogleMap _map1;
	private MapOptions mapOptions;	

	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()
	 {
	     _bounds = await LatLngBounds.CreateAsync(_map1.JsRuntime);
	 }		
}

OR Render markers with Blazor (currently only with v=beta version of google-maps, and specify a MapId)

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

<h1>Google Map</h1>
<AdvancedGoogleMap @ref="@_map1" Id="map1" Options="@mapOptions">
    @foreach (var markerRef in Markers)
    {
        <MarkerComponent 
            @key="markerRef.Id" 
            Lat="@markerRef.Lat" 
            Lng="@markerRef.Lng" 
            Clickable="@markerRef.Clickable" 
            Draggable="@markerRef.Draggable" 
            OnClick="@(() => markerRef.Active = !markerRef.Active)"
            OnMove="pos => markerRef.UpdatePosition(pos)">
            <p>I am a blazor component</p>
        </MarkerComponent>
    }
</AdvancedGoogleMap>
@code {
    private List<MarkerData> Markers =
    [
        new MarkerData { Id = 1, Lat = 13.505892, Lng = 100.8162 },
    ];
	private AdvancedGoogleMap? _map1;
	private MapOptions mapOptions =new MapOptions()
	{
		Zoom = 13,
		Center = new LatLngLiteral()
		{
			Lat = 13.505892,
			Lng = 100.8162
		},
		MapId = "DEMO_MAP_ID", //required for blazor markers
		MapTypeId = MapTypeId.Roadmap
	};	

    public class MarkerData
    {
        public int Id { get; set; }
        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;
        }
    }
}

Samples

Please check server side samples https://github.com/rungwiroon/BlazorGoogleMaps/tree/master/ServerSideDemo which are most to date

ClientSide demos online https://rungwiroon.github.io/BlazorGoogleMaps/mapEvents

Breaking change from 4.0.0 Migrate to .NET 8 #286.

Breaking change from 3.0.0 Migrate from Newtonsoft.Json to System.Text.Json.

Breaking change from 2.0.0 LatLngLiteral constructor's parameters order changed #173

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on BlazorGoogleMaps:

Package Downloads
templar-common-libary

Package Description

Magiq.Blazor

Provides views and services to be used in Blazor Client and Server projects.

AeroBlazor

A blazor library, extending MudBlazor

Microfrontend.one

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.13.0 1,079 6/5/2025
4.12.2 400 6/2/2025
4.12.1 347 6/1/2025
4.12.0 316 5/28/2025
4.11.3 149 5/28/2025
4.11.2 1,384 5/13/2025
4.11.1 5,573 4/20/2025
4.11.0 491 4/14/2025
4.10.1 1,683 4/1/2025
4.10.0 560 3/30/2025
4.9.5 238 3/28/2025
4.9.4 180 3/27/2025
4.9.3 5,030 2/23/2025
4.9.2 13,382 12/14/2024
4.9.1 4,795 11/21/2024
4.9.0 2,031 11/17/2024
4.8.0 290 11/16/2024
4.7.15 127 11/16/2024
4.7.14 11,419 10/9/2024
4.7.13 7,638 10/3/2024
4.7.12 1,593 9/29/2024
4.7.11 10,220 8/29/2024
4.7.10 989 8/28/2024
4.7.9 138 8/28/2024
4.7.8 189 8/28/2024
4.7.7 1,653 8/25/2024
4.7.6 5,050 8/12/2024
4.7.5 202 8/11/2024
4.7.4 152 8/10/2024
4.7.3 2,389 7/29/2024
4.7.2 2,853 7/25/2024
4.7.1 7,050 7/8/2024
4.7.0 321 7/4/2024
4.6.2 368 7/2/2024
4.6.1 202 7/1/2024
4.6.0 1,092 6/26/2024
4.5.0 934 6/22/2024
4.4.2 4,870 6/12/2024
4.4.1 252 6/11/2024
4.4.0 232 6/10/2024
4.3.0 7,142 5/15/2024
4.2.0 6,266 4/25/2024
4.1.2 8,645 3/21/2024
4.1.1 493 3/20/2024
4.1.0 37,847 2/2/2024
4.0.3 939 1/18/2024
4.0.2 4,499 12/20/2023
4.0.1 1,889 12/17/2023
4.0.0 275 12/15/2023
3.3.2 25,656 12/15/2023
3.3.1 9,946 12/5/2023
3.2.5 2,664 11/23/2023
3.2.4 195 11/23/2023
3.2.3 8,415 10/30/2023
3.2.2 1,829 10/25/2023
3.2.1 271 10/25/2023
3.2.0 4,752 9/18/2023
3.1.4 3,888 9/9/2023
3.1.3 595 9/3/2023
3.1.2 7,811 8/1/2023
3.1.1 5,210 7/19/2023
3.1.0 2,084 7/10/2023
3.0.8 296 7/9/2023
3.0.7 11,231 6/9/2023
3.0.6 6,968 5/7/2023
3.0.5 3,828 4/13/2023
3.0.4 502 4/11/2023
3.0.3 1,417 4/6/2023
3.0.2 641 4/3/2023
3.0.1 382 4/1/2023
3.0.0 1,892 3/28/2023
2.5.7 12,822 3/14/2023
2.5.6 991 3/13/2023
2.5.5 3,943 2/24/2023
2.5.4 10,356 2/11/2023
2.5.3 986 2/6/2023
2.5.2 3,132 1/20/2023
2.5.1 1,245 1/17/2023
2.4.4 12,152 12/13/2022
2.4.3 6,936 11/29/2022
2.4.2 411 11/29/2022
2.4.1 1,560 11/25/2022
2.3.1 2,888 11/14/2022
2.2.6 26,977 9/5/2022
2.2.5 1,642 8/27/2022
2.2.4 474 8/27/2022
2.2.3 1,475 8/22/2022
2.2.2 607 8/19/2022
2.2.1 31,418 6/28/2022
2.2.0 3,028 6/20/2022
2.1.1 2,488 5/23/2022
2.1.0 2,271 5/3/2022
2.0.6 767 4/30/2022
2.0.5 1,778 4/21/2022
2.0.4 1,527 4/15/2022
2.0.3 1,180 4/1/2022
2.0.2 615 3/30/2022
2.0.1 550 3/30/2022
2.0.0 1,269 3/29/2022
1.5.5 11,659 2/24/2022
1.5.4 725 2/21/2022
1.5.3 2,032 2/16/2022
1.5.2 753 2/15/2022
1.5.1 4,208 2/7/2022
1.4.2 7,151 12/15/2021
1.4.1 7,171 12/8/2021
1.4.0 427 12/7/2021
1.3.0 591 12/2/2021
1.2.1 17,543 10/11/2021
1.1.8 1,407 9/27/2021
1.1.7 586 9/25/2021
1.1.6 459 9/23/2021
1.1.5 1,437 9/16/2021
1.1.4 1,340 9/12/2021
1.1.3 619 9/9/2021
1.1.2 823 9/7/2021
1.1.1 1,366 8/30/2021
1.0.17 2,303 7/27/2021
1.0.16 898 7/17/2021
1.0.15 9,056 4/29/2021
1.0.14 5,900 4/9/2021
1.0.13 32,075 3/18/2021
1.0.12 4,464 2/13/2021
1.0.11 639 2/10/2021
1.0.10 496 2/10/2021
1.0.9 474 2/10/2021
1.0.8 843 2/3/2021
1.0.7 4,209 1/30/2021
1.0.6 550 1/28/2021
1.0.5 1,025 1/18/2021
1.0.4 715 1/14/2021
1.0.3 510 1/13/2021
1.0.2 1,474 1/1/2021
1.0.1 923 12/25/2020
1.0.0 530 12/25/2020
0.9.3 526 12/25/2020
0.9.2 773 12/22/2020
0.9.1 1,235 12/4/2020
0.9.0 6,973 10/23/2020
0.8.1 1,154 10/4/2020
0.8.0 1,840 9/16/2020
0.7.1 1,717 8/9/2020
0.6.14 603 8/4/2020
0.6.13 760 8/2/2020
0.6.12 787 7/28/2020
0.6.11 581 7/27/2020
0.6.10 3,395 7/20/2020
0.6.9 685 7/14/2020
0.6.8 720 7/9/2020
0.6.7 665 7/7/2020
0.6.6 734 6/30/2020
0.6.5 1,117 6/4/2020
0.6.4 1,656 5/16/2020
0.6.3 1,090 5/5/2020
0.6.2 1,680 4/16/2020
0.6.1 785 3/27/2020
0.6.0 596 3/27/2020
0.5.9 617 3/26/2020
0.5.8 1,010 3/25/2020
0.5.7 596 3/25/2020
0.5.6 700 3/17/2020
0.5.5 1,617 3/7/2020
0.5.4 972 2/9/2020
0.5.3 697 2/8/2020
0.5.2 1,891 1/24/2020
0.5.1-alpha 898 12/9/2019
0.4.8-alpha 503 12/1/2019
0.4.7-alpha 590 10/18/2019
0.4.6-alpha 544 9/26/2019
0.4.5-alpha 400 8/20/2019
0.4.0-alpha 413 6/15/2019
0.3.0 947 6/1/2019
0.1.0 1,078 2/2/2019