BlazorGoogleMaps 4.9.3

dotnet add package BlazorGoogleMaps --version 4.9.3                
NuGet\Install-Package BlazorGoogleMaps -Version 4.9.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.9.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BlazorGoogleMaps --version 4.9.3                
#r "nuget: BlazorGoogleMaps, 4.9.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.
// Install BlazorGoogleMaps as a Cake Addin
#addin nuget:?package=BlazorGoogleMaps&version=4.9.3

// Install BlazorGoogleMaps as a Cake Tool
#tool nuget:?package=BlazorGoogleMaps&version=4.9.3                

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. 
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.9.3 2,094 a month ago
4.9.2 9,040 3 months ago
4.9.1 4,182 4 months ago
4.9.0 2,007 4 months ago
4.8.0 277 4 months ago
4.7.15 112 4 months ago
4.7.14 9,384 5 months ago
4.7.13 4,680 6 months ago
4.7.12 1,499 6 months ago
4.7.11 9,483 7 months ago
4.7.10 716 7 months ago
4.7.9 131 7 months ago
4.7.8 180 7 months ago
4.7.7 1,467 7 months ago
4.7.6 4,749 7 months ago
4.7.5 196 7 months ago
4.7.4 143 7 months ago
4.7.3 2,139 8 months ago
4.7.2 2,261 8 months ago
4.7.1 5,785 8 months ago
4.7.0 313 9 months ago
4.6.2 358 9 months ago
4.6.1 195 9 months ago
4.6.0 1,011 9 months ago
4.5.0 923 9 months ago
4.4.2 4,499 9 months ago
4.4.1 247 9 months ago
4.4.0 221 9 months ago
4.3.0 6,715 5/15/2024
4.2.0 6,019 4/25/2024
4.1.2 8,490 3/21/2024
4.1.1 486 3/20/2024
4.1.0 31,645 2/2/2024
4.0.3 916 1/18/2024
4.0.2 4,465 12/20/2023
4.0.1 1,884 12/17/2023
4.0.0 266 12/15/2023
3.3.2 18,752 12/15/2023
3.3.1 9,599 12/5/2023
3.2.5 2,642 11/23/2023
3.2.4 190 11/23/2023
3.2.3 8,027 10/30/2023
3.2.2 1,824 10/25/2023
3.2.1 261 10/25/2023
3.2.0 4,707 9/18/2023
3.1.4 3,834 9/9/2023
3.1.3 586 9/3/2023
3.1.2 7,781 8/1/2023
3.1.1 5,190 7/19/2023
3.1.0 2,067 7/10/2023
3.0.8 285 7/9/2023
3.0.7 11,021 6/9/2023
3.0.6 6,666 5/7/2023
3.0.5 3,719 4/13/2023
3.0.4 484 4/11/2023
3.0.3 1,404 4/6/2023
3.0.2 623 4/3/2023
3.0.1 367 4/1/2023
3.0.0 1,877 3/28/2023
2.5.7 12,692 3/14/2023
2.5.6 979 3/13/2023
2.5.5 3,892 2/24/2023
2.5.4 10,273 2/11/2023
2.5.3 972 2/6/2023
2.5.2 3,033 1/20/2023
2.5.1 1,234 1/17/2023
2.4.4 11,672 12/13/2022
2.4.3 6,844 11/29/2022
2.4.2 396 11/29/2022
2.4.1 1,543 11/25/2022
2.3.1 2,876 11/14/2022
2.2.6 26,854 9/5/2022
2.2.5 1,624 8/27/2022
2.2.4 460 8/27/2022
2.2.3 1,453 8/22/2022
2.2.2 593 8/19/2022
2.2.1 29,921 6/28/2022
2.2.0 3,009 6/20/2022
2.1.1 2,468 5/23/2022
2.1.0 2,251 5/3/2022
2.0.6 748 4/30/2022
2.0.5 1,757 4/21/2022
2.0.4 1,506 4/15/2022
2.0.3 1,157 4/1/2022
2.0.2 593 3/30/2022
2.0.1 530 3/30/2022
2.0.0 1,249 3/29/2022
1.5.5 11,597 2/24/2022
1.5.4 702 2/21/2022
1.5.3 1,985 2/16/2022
1.5.2 727 2/15/2022
1.5.1 4,183 2/7/2022
1.4.2 7,038 12/15/2021
1.4.1 6,778 12/8/2021
1.4.0 403 12/7/2021
1.3.0 560 12/2/2021
1.2.1 17,205 10/11/2021
1.1.8 1,382 9/27/2021
1.1.7 561 9/25/2021
1.1.6 435 9/23/2021
1.1.5 1,408 9/16/2021
1.1.4 1,314 9/12/2021
1.1.3 593 9/9/2021
1.1.2 798 9/7/2021
1.1.1 1,339 8/30/2021
1.0.17 2,244 7/27/2021
1.0.16 874 7/17/2021
1.0.15 9,009 4/29/2021
1.0.14 5,796 4/9/2021
1.0.13 31,098 3/18/2021
1.0.12 4,433 2/13/2021
1.0.11 608 2/10/2021
1.0.10 464 2/10/2021
1.0.9 442 2/10/2021
1.0.8 810 2/3/2021
1.0.7 4,031 1/30/2021
1.0.6 518 1/28/2021
1.0.5 994 1/18/2021
1.0.4 684 1/14/2021
1.0.3 479 1/13/2021
1.0.2 1,441 1/1/2021
1.0.1 891 12/25/2020
1.0.0 497 12/25/2020
0.9.3 492 12/25/2020
0.9.2 741 12/22/2020
0.9.1 1,200 12/4/2020
0.9.0 6,934 10/23/2020
0.8.1 1,121 10/4/2020
0.8.0 1,808 9/16/2020
0.7.1 1,682 8/9/2020
0.6.14 572 8/4/2020
0.6.13 729 8/2/2020
0.6.12 755 7/28/2020
0.6.11 548 7/27/2020
0.6.10 2,992 7/20/2020
0.6.9 653 7/14/2020
0.6.8 684 7/9/2020
0.6.7 633 7/7/2020
0.6.6 701 6/30/2020
0.6.5 1,074 6/4/2020
0.6.4 1,620 5/16/2020
0.6.3 1,022 5/5/2020
0.6.2 1,641 4/16/2020
0.6.1 749 3/27/2020
0.6.0 560 3/27/2020
0.5.9 580 3/26/2020
0.5.8 974 3/25/2020
0.5.7 557 3/25/2020
0.5.6 664 3/17/2020
0.5.5 1,551 3/7/2020
0.5.4 933 2/9/2020
0.5.3 661 2/8/2020
0.5.2 1,855 1/24/2020
0.5.1-alpha 860 12/9/2019
0.4.8-alpha 465 12/1/2019
0.4.7-alpha 551 10/18/2019
0.4.6-alpha 505 9/26/2019
0.4.5-alpha 364 8/20/2019
0.4.0-alpha 372 6/15/2019
0.3.0 905 6/1/2019
0.1.0 1,030 2/2/2019