Top

Maps


you have to install google map


 npm i @angular/google-maps
Map at a specified location with Marker
<!-- Map html start -->
  <google-map height="500px" width="100%" [zoom]="zoom">
     @for(marker of markers; track marker){
       <map-marker #markerElem [position]="marker.position"
           [label]="marker.label" [title]="marker.title" [options]="marker.options"
           (mapClick)="openInfo(markerElem, marker.info)">
       </map-marker>
     }
</google-map>
  
To use google map following type script files

 import { Component } from '@angular/core';
  import { GoogleMap, MapMarker } from '@angular/google-maps';
  
  interface IMarkerPosition {
    lat: number;
    lng: number;
  }
  
  interface IMarkerLabel {
    color: string;
    text: string;
  }
  
  interface IGoogleMapMarkers {
    position: IMarkerPosition;
    label: IMarkerLabel;
  }
  
  @Component({
    selector: 'app-google-map',
    templateUrl: './google-map.html',
    styleUrls: ['./google-map.scss'],
    imports: [GoogleMap, MapMarker],
  })
  export class GoogleMaps {
    public asiaMapOptions: google.maps.MapOptions = {
      center: { lat: 47.5162, lng: 100.2167 },
      zoom: 3,
    };
  
    public worldMapOption: google.maps.MapOptions = {
      center: { lat: 0, lng: 0 },
      zoom: 2,
    };
  
    public usaMapOptions: google.maps.MapOptions = {
      center: { lat: 37.0902, lng: -95.7129 },
      zoom: 4,
    };
  
    public indiaMapOptions: google.maps.MapOptions = {
      center: { lat: 20.5937, lng: 78.9629 },
      zoom: 4,
    };
  
    public markers: IGoogleMapMarkers[];
    public zoom: number;
  
    constructor() {
      this.markers = [];
  
      this.markers.push({
        position: {
          lat: 32.4279,
          lng: 53.688,
        },
        label: {
          color: 'black',
          text: 'Iran',
        },
      });
  
      this.markers.push({
        position: {
          lat: 33.9391,
          lng: 67.71,
        },
        label: {
          color: 'black',
          text: 'Afghanistan',
        },
      });
  
      this.markers.push({
        position: {
          lat: 23.0225,
          lng: 72.5714,
        },
        label: {
          color: 'black',
          text: 'Ahmadabad',
        },
      });
    }
  }

you have to install Leaflet map


 npm i @bluehalo/ngx-leaflet

Simple Map

<!-- Map html start -->

     <div class="col-sm-6">
      <div class="card">
        <div class="card-header card-no-border pb-0">
          <h3>Simple Map</h3>
        </div>
        <div class="card-body">
           <div style="height: 500px; z-index: 0;" leaflet [leafletOptions]="options1"></div>
        </div>
      </div>
    </div>
             
To use Leaflet Maps following type script files

  import { HttpClient } from '@angular/common/http';
  import { Component } from '@angular/core';
  import { LeafletModule } from '@bluehalo/ngx-leaflet';
  import * as L from 'leaflet';
  import { PageWrapperComponent } from "../../../shared/components/page-wrapper/page-wrapper";
  import { CardComponent } from "../../../shared/components/card/card";
  
  @Component({
      selector: 'app-leaflet-map',
      templateUrl: './leaflet-map.html',
      styleUrl: './leaflet-map.scss',
      imports: [LeafletModule, PageWrapper, Card]
  })
  
  export class LeafletMap{
  
  
  
    options1 = {
      layers: [
        L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
          maxZoom: 18,
          attribution: '...',
        }),
      ],
      zoom: 5,
      center: L.latLng(46.879966, -121.726909),
    };
  
  }