How to add Google map and Marker to your Application using AngularJS ? Last Updated : 16 Jun, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report The objective is to add a Google Map and a Marker in Angular application. When the user will click on a particular location on the map, the marker will be added to that particular location. For reaching the goal we will use AGM (Angular Google Maps) and its components that will make the solution very easy. What is Angular Google Maps (AGM) ? AngularJS provides Angular Google Maps Components used to integrate Google Maps services in an application. AGM has components that can be directly used in the application. Approach and Solution: The steps to use Angular Google Maps are given below: Install AGM to your local angular project using following command. npm install @agm/core --saveGenerate an API key to use the services. Go to https://developers.google.com/maps/documentation/javascript/get-api-key and follow all the steps to create an API key.Make sure your API is enabled, to enable your API follow the steps from this link https://support.google.com/googleapi/answer/6158841?hl=en Import AgmCoreModule to your applications import { AgmCoreModule } from '@agm/core'; Add AgmCoreModule.forRoot where you have to put the created API key to apiKey (apiKey:"your API key here"). imports: [ AgmCoreModule.forRoot({ apiKey:"your API key here" })]app.module.ts: javascript import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AgmCoreModule } from '@agm/core'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, AppRoutingModule, AgmCoreModule.forRoot({ apiKey:"your API Key" }) ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } In HTML file component selector agm-map is used to introduce map where latitude and longitude is bind to variables latitude and longitude. The click on map i.e. (mapClick) event is used to pass event with function that contains latand lng coordinates of click on the map. For marker agm-marker selector is used where the same latitude and longitude are bind to local variables. app.component.html: html <agm-map [latitude]="latitude" [longitude]="longitude" (mapClick)="location($event)"> <agm-marker [latitude]="latitude" [longitude]="longitude"> </agm-marker> </agm-map> In the TypeScript file, the function is defined that takes the coordinates and binds it to a local variable which is used to set the marker on the click of the map. app.component.ts: javascript import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { latitude=51.678418; longitude=7.809007; location(x){ this.latitude=x.coords.lat; this.longitude=x.coords.lng; } } Output: Run the development server to get the map and click on the map to add the marker to the location you want. Comment More infoAdvertise with us Next Article How to add Google map inside html page without using API key ? T taran910 Follow Improve Article Tags : Web Technologies AngularJS AngularJS-Misc Similar Reads How to Add Google Locations Autocomplete to your Angular Application ? The task here is to Add Google Locations Autocomplete to your Angular Application. When user will enter some text for a location in the Textfield, he/she will get locations recommendations and can autocomplete the location. For achieving the target, we will use ngx-google-places-autocomplete angular 3 min read How To Add Google Maps With A Marker to a Website Google Maps is a web mapping service developed by Google. It offers satellite imagery, street maps, 360° panoramic views of streets (Street View), real-time traffic conditions (Google Traffic), and route planning for traveling by foot, car, bicycle (in beta), or public transportation. To add a Googl 3 min read How to add click event to Google Map markers stored in an array in JavaScript ? To add a click event to markers stored in an array, you will first need to iterate over the array of markers using a loop. Then, within the loop, you can bind a click event to each marker. Syntax:var markers = [marker1, marker2, marker3]; // Array of markersfor (var i = 0; i < markers.length; i++ 3 min read How to add Google map inside html page without using API key ? There are two ways to add google maps inside HTML page: Using API key Without using API key To learn first case you can follow the article while to learn other one follow this article. To insert google map inside the HTML page, follow the steps: Go to the google maps and search your desired location 2 min read Deployment of Angular Application using Github Pages There are various methods to deploy Angular Application such as Github Pages, Heroku, Firebase, etc. The Github provides the simplest way of all using the Github Pages. Steps to Create and Deploy Sample Angular Application to Github Pages: Install Node.js: a. Windows b. LinuxInstall Angular - CLICre 2 min read Create a Map with Google Map Api using React-Native In this project, we'll explore how to integrate Google Maps into a React Native application. We'll create a dynamic map that allows users to view their current location and interact with markers on the map. This project aims to provide a practical guide for developers looking to incorporate maps int 3 min read Like