angular agm

Solutions on MaxInterview for angular agm by the best coders in the world

showing results for - "angular agm"
Fabiana
14 Jun 2016
1Step 1: Creating new project
2Create a new project using command ng new gmaps-ng5
3Step 2: Install Google Maps types for typescript support.
4Run command npm install --save @types/googlemaps
5Step 3: Link Google Maps JavaScript CDN inside index.html
6<script src="http://maps.googleapis.com/maps/api/js"></script>
7NOTE: Make sure you put your Google Map API Key here. You can get one from `https://developers.google.com/maps/documentation/javascript/get-api-key`. If not, after free usage, Google Map will start showing watermark.
8With above steps, you are all set to start working with Google Maps (GMap).
9Step 4: Next, let’s add a placeholder <div> for GMap
10<div #gmap style="width:100%;height:400px"></div>
11Step 5: Initialize GMap inside component
12
13	import { ViewChild } from '@angular/core';
14	import { } from '@types/googlemaps';
15
16	export class AppComponent {  
17	  @ViewChild('gmap') gmapElement: any;
18	  map: google.maps.Map;
19
20	  ngOnInit() {
21		var mapProp = {
22		  center: new google.maps.LatLng(18.5793, 73.8143),
23		  zoom: 15,
24		  mapTypeId: google.maps.MapTypeId.ROADMAP
25		};
26		this.map = new google.maps.Map(this.gmapElement.nativeElement, mapProp);
27	  }
28	}
29
30Let’s break it down.
31import { } from '@types/googlemaps';
32
33First we shall import Google Maps types that we have installed in step 2. This is great help during development as you can work with strong types instead of vague any type. Apart from that, you shall also get intellisense if your IDE can understand type definition files.
34Access <div #gmap>: gmapElement is a reference to <div #gmap> inside app.component.html file. ViewChild directive creates a direct link between <div> element and a gmapElement member variable.
35ngOnInit(): Inside ngOnInit() life cycle hook, we shall create configuration object for GMap specifying default center, zoom level and map type. We shall pass this object to google.maps.Map constructor which shall return new Map object which we shall retain in member variable map for later access.
36Running application:
37Run application using ng serve and you should see Google Map inside browser. Congrats!! See, it was easy, told ya!
38Perform Map operations
39By default Google Map control shall render map as well as have few controls for changing zoom, full screen etc. You can access native Google Maps API via Angular.
40
41Change Map type
42
43	<div class="col-md-3 col-sm-12 col-xs-12">
44	  <button (click)="setMapType('terrain')" class="btn btn-primary">Terrain</button>
45	  <button (click)="setMapType('satellite')" class="btn btn-danger">Satellite</button>
46	  <button (click)="setMapType('roadmap')" class="btn btn-warning">Road Map</button>
47	</div>
48	
49	setMapType(mapTypeId: string) {
50		this.map.setMapTypeId(mapTypeId)    
51	}
52
53We have map member variable inside our AppComponent class. Using this variable, we can call native GMap API for example, setMapTypeId. We have three buttons which pass map type ID to click handler to be passed to setMapTypeId function.
54Navigate Map via Latitude and Longitude
55Let’s create a HTML form for user to enter Latitude and Longitude.
56
57	<form class="form-inline" #form="ngForm" (ngSubmit)="setCenter($event)" ac>
58	  <div class="form-group">
59		<input type="text" class="form-control" name="latitude" [(ngModel)]="latitude" placeholder="Enter latitude" required>
60	  </div>
61	  <div class="form-group">
62		<input type="text" class="form-control" name="longitude" [(ngModel)]="longitude" placeholder="Enter longitude" required>
63	  </div>
64	  <button type="submit" class="btn btn-primary" [disabled]="form.invalid">Go</button>
65	</form>
66
67Once user submit the form by entering Latitude and Longitude, we shall call native setCenter GMap API. This function takes object of LatLng type hence we shall pass lat/long as a parameter to LatLng constructor.
68Notice e.preventDefault() function call. It is to avoid refreshing complete page on form submit.
69
70	export class AppComponent {
71	  latitude:number;
72	  longitude:number;
73
74	  setCenter(e:any){
75		e.preventDefault();
76		this.map.setCenter(new google.maps.LatLng(this.latitude, this.longitude));
77	  }
78	}
Kahina
19 Jun 2019
1npm install @agm/core
2
3// on your module
4import { AgmCoreModule } from '@agm/core';
5
6imports: [
7    AgmCoreModule.forRoot({
8      apiKey: ''  // create a Google API Key and enable "Maps JavaScript API" for that API
9    })
10  ]
11
12// on you component
13  title = 'My first AGM project';
14  lat = 51.678418;
15  lng = 7.809007;
16
17// on your html
18<agm-map [latitude]="lat" [longitude]="lng" style="height:150px">
19    <agm-marker [latitude]="lat" [longitude]="lng"></agm-marker>
20</agm-map>
queries leading to this page
angular google mapsgoogle maps angular 8add google maps api angulargoogle map javascript angulargoogle map angulargoogle maps angulargoogle maps angularangular google maps official librarygoogle map in angular 7angular 9 google maps componentgoogle maps with angularamngular mapsintegrate google maps angularangularjs google maps exampleangular using google mapnew google maps angulargoogle maps angularjs examplehow to use google maps in your project with angulargoogle map angular 9agm in angular 12maker plot angular in goole map google maps angular docsgoogle map angular 5angular new google maps mause google map in angular 9angular 12 google mapsangular and google mapsgoogle map with angular 10angularu google mapangular 11 google maps exampleangular google maps in angularjavascript google map with angularjsangular google maps javascript apiadding google map in html angular exampleangualr google mapsintegrare google maps angularhow to integrate google maps in angularangular agm mapangular google maps componentgoogle maps angularjs controlagm angular 8google map component angular 9agm angulargoogle map angular 11google maps in angular 11how to use gmap map javascript api in angulargoogle maps on angulargoogle maps angular exampleangular google marker linkgoogle maps in angularangularjs example google mapusing google maps with angular 11google map angular materialgoogle maps api in angulargoogle maps angular tutorialangular g maps using google maps on angular projecthow to use google maps in angular 10implement google map angulargoogle maps in angulargoogle maps for angularangular google maps linkgoogle maps angular 11angluar google mapsgoogle map angularangular 6 google maps examplegoogle maps library angulargoogle maps agm angular 2 2b componentjs google map api angularadding map in angularuse google maps angularangular google map freegoogle map for angular 11google maps pour angular 10angular google mappsag map angularhow to use the google maps in angular 9google map component angularusing google maps with angulagooglemaps angulargoogle maps component angulargoogle maps for angular 11angular google maps tutorialgoogle map with angulargoogle map in angular google maps map angularangular new google maps mapgoogle maps angular 11google maps in component 7dangulargoogle maps angular creationembed map in angularangular 12 google js mapsangular google maps docsuse google maps in angulargoogle maps platform with angularangular google maps optionshow to use google maps with angulargoogle maps angualragm for angular 12add google maps angularangular app google mapsusing google maps with angulargoogle maps types angularangular google mapusing google maps in angualrgoogle map in angularagm in angulargoogle maps javascript angularangular 2 agmagm angular appangular2 google mapinit google map in angulargoogle maps api in angular 8angular google maps pluginangular googlemap angular 11 google mapsgmaps angulargoogle maps in angular 4google maps for angular 9google maps implementation angularangular google maps bowerhow to use google map in angularangularjs google mapsapi google maps angular angular 11 agm google maps with angular 10google map implementation in angulargoogle maps angular 10angular agmimplement google maps in angular 6google maps angularangular here mapsusing google maps in angular appintegrate google maps with angularangular google maps documentationlibrary google maps angular 40angular google mapsgoogle map in angular 12google maps in angular 12angular 2fgoogle maps for angular 11google maps for angular 10angular 8 google maps exampleangular mapsangular google maps mapangular js google mapsangular google mapofficial angular google maps componentgoogle maps javascript api angularusing goole maps api in angularagm angular 10 40angular 2fgoogle maps apiangular google maps version for angular 9using google maps angualrangular 2fgoogle maps usage angular 5google navigation in angulargoogle maps angular 12google maps angular libraryangular 11 2f10 google maps example tutorialgoogle maps library angular 9google map in angular 10google map in angular 11angular maps componentgoogle maps on angular 10angularjs google mapangular google maps geofencegoogle maps types angularintegrate google maps with angular 11how to use google maps api in angularagm angular google maphow to use google map in angular app 40angular 2fgoogle maps examplegoogle maps angualr apiuse google map with angularusing google maps in angularangular google maps apimaps google com maps api javascript in angulargoogle maps integration in angular 9display google maps angularhow to implement google maps in angularimplement google maps in angularangular 9 google maps official libraryintegrate google maps in angularangular 5 google maps version 40angular 2fgoogle maps documentationangularjs and google mapsangular material google maps angular google maps examplehow to embed google maps in angularangular import googlemapsgoogle map in angular 8angular 2fgoogle mapagm angular 11angular 5 google mapuse google maps in angularjsangular map componenthow add google map in angularangular 5 google mapsangular and google mapangular googlemapsangular google map moduleangular 10 google mapsgoogle map for angularusing map without google map in angulargoogle maps angular tsangular google mapangular foofl mapgoogle map with js angulargoogle maps angular componentangular 9 google mapsmake an angular app that uses google mapsangular google maps angular 12angular component google mapsangular 10 google maps exampleload google map in angular 6 using map jsgoogle maps api angulargoogle maps embed api angularangular google maps integrationgoole map with angularangular maps angulargoogle map component from angulargoogle map angular moduleangular google map examplegoogle maps in angular routingintegrate google maps with angular 11google maps module angularangular google maps angular uigoogle maps docs for angularangular1 google mapangular google map typeshow to use google maps in angular 6googlemap with angulargoogle map angular 10angular google mapsangular agm