<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jyotikant Nadi on Medium]]></title>
        <description><![CDATA[Stories by Jyotikant Nadi on Medium]]></description>
        <link>https://medium.com/@jyotikanta.n?source=rss-7581c0162276------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*cfD9UEDtQQueV3pN</url>
            <title>Stories by Jyotikant Nadi on Medium</title>
            <link>https://medium.com/@jyotikanta.n?source=rss-7581c0162276------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 02:21:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jyotikanta.n/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Google Maps Autocomplete API Integration With Angular 2+/ Angular 10.]]></title>
            <link>https://medium.com/@jyotikanta.n/google-maps-autocomplete-api-integration-with-angular-2-angular-10-13ca2604a3bd?source=rss-7581c0162276------2</link>
            <guid isPermaLink="false">https://medium.com/p/13ca2604a3bd</guid>
            <category><![CDATA[google-maps-autocomplete]]></category>
            <category><![CDATA[autocomplete]]></category>
            <category><![CDATA[angular-google-map]]></category>
            <category><![CDATA[google-maps-javascript]]></category>
            <category><![CDATA[google-maps-integration]]></category>
            <dc:creator><![CDATA[Jyotikant Nadi]]></dc:creator>
            <pubDate>Mon, 27 Jul 2020 18:10:05 GMT</pubDate>
            <atom:updated>2020-07-27T18:17:53.287Z</atom:updated>
            <content:encoded><![CDATA[<p>This Tutorial Is Based on <a href="https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform">Google Maps Example </a>, With Simple JavaScript Knowledge .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/1*bQ0k7AuUQWMFAZAGByj71g.png" /><figcaption>Google Maps Autocomplete</figcaption></figure><blockquote><strong><em>Updated On 28 July 2020 -Angular Version 10</em></strong></blockquote><blockquote><strong><em>Pre-requisites</em></strong> :</blockquote><p><a href="https://cli.angular.io/"><em>Angular CLI</em></a> , <a href="https://www.google.com/search?newwindow=1&amp;q=javascript+tutorial&amp;oq=javascript+Tutorial"><em>JavaScript </em></a><em>, </em><a href="https://getbootstrap.com/docs/4.4/getting-started/introduction/"><em>Bootstrap </em></a><em>4</em></p><blockquote><strong><em>Collect An API Key From Google</em></strong></blockquote><p>Detailed <a href="https://developers.google.com/maps/documentation/javascript/get-api-key"><em>steps to generate key</em></a> . Note that you’ll need to enter payment information, but there are plenty of ways to use the API for free! For this tutorial, I won’t get into the specifics of authentication and API key restrictions.</p><p><strong>Step 1: Create a new Angular project</strong></p><p>If You Already Installed Angular CLI , You Can skip this Step 1.</p><pre>npm install -g @angular/cli</pre><p><strong>Step 2: Create a new Angular project</strong></p><p>If you have the <a href="https://cli.angular.io/">Angular CLI</a> and the <a href="https://angular.io/guide/quickstart">pre-requisites</a> for developing Angular apps installed, simply run</p><pre>ng new ng-gmaps</pre><p>in a command prompt to create a new project. In this case, my project will be called ng-gmaps. The Angular CLI is a very powerful tool that can streamline updates between Angular versions, create new projects, and easily add components and services to your project (among many other functions).</p><p><strong><em>Step 3: Install Google Maps types for typescript support</em></strong></p><p>Change Directory to your project directory and install googlemaps type, by run</p><pre>cd ng-gmaps<br>npm install --save @types/googlemaps</pre><p>This package imports the TypeScript type definitions for the Google Maps Javascript API and allows for strong types and intellisense in your Angular project and IDE (if supported).</p><p><strong><em>Step 4: Link to the Google Maps JavaScript file</em></strong></p><p>Open the index.html file and add in the following script tag within the &lt;body&gt;&lt;/body&gt; section. Replace API-KEY with the API key you procured in step 1. I added it below the &lt;app-root&gt;&lt;/app-root&gt; tag, not sure if the order matters.</p><pre>&lt;script src=&quot;https://maps.googleapis.com/maps/api/js?key=&lt;API_KEY&gt; &amp;libraries=places&amp;v=weekly&quot;defer&gt;&lt;/script&gt;</pre><p><strong><em>Step 5: Add the HTML element to house the map</em></strong></p><p>For simplicity, you can add this to your AppComponent, but this will also work in sub components. In app.component.html, add</p><pre>&lt;div id=&quot;autocomplete-container&quot;&gt; &lt;/div&gt;                                                                        &lt;div id=&quot;mapEle&quot;&gt;&lt;/div&gt;                                                                             &lt;div class=&quot;row&quot;&gt;                                                                                      &lt;div class=&quot;col-12&quot; id=&quot;autocResult&quot;&gt; &lt;/div&gt;                                                           &lt;/div&gt;                                                                       </pre><p>Here We added one division with id ‘autocomplete-container’ for Autocomplete Input ,id ‘mapEle’ to embed with map and id ‘autocResult’ to show selected Address_Result.</p><p><strong><em>Step 6: Import the Google Map types into component</em></strong></p><p>In the component file where you placed the map placeholder element (in this case, app.component.ts), we need to import the Google Map TypeScript definitions. At the top of app.component.ts, I’ll add</p><p>*for Angular 8+</p><pre>/// &lt;reference types=&quot;@types/googlemaps&quot; /&gt;</pre><p>*for till Angular 7</p><pre>import {} from &#39;googlemaps&#39;;</pre><p>At this point, if you run your application using</p><pre>ng serve</pre><p>you’ll probably see an error like</p><pre>@types/googlemaps/index.d.ts is not a module</pre><p>Oh no! Red squigglies! Don’t fret, just create a file called index.d.ts directly within your src directory and add the following line</p><pre>declare module &#39;googlemaps&#39;;</pre><p>If you’re still seeing the error, try restarting the application using ng serve.</p><p><strong><em>Step 7: Initialize the map</em></strong></p><p>Still working within the component file, let’s initialize the map within the OnInit lifecycle hook.Add some variables within your component.</p><pre>map: google.maps.Map;                                                                                            markers: google.maps.Marker[] = [];                                                                         lat: number = null;                                                                                lng: number = null;                                                                      </pre><p>Within the OnInit lifecycle hook embed Autocomplete Input field</p><p>*Autocomplete Input Embed</p><pre>let node = document.createElement(&quot;INPUT&quot;);      node.setAttribute(&quot;type&quot;, &quot;text&quot;);                           node.setAttribute(&quot;placeholder&quot;, &quot;Enter a location&quot;);              node.setAttribute(&quot;class&quot;, &quot;form-control&quot;)                                      node.setAttribute(&quot;id&quot;, &quot;input_autoc&quot;)                                                         // Create the autocomplete object, restricting the search                           // predictions to geographical location types.                                     let autocomplete = new google.maps.places.Autocomplete(node, {});        // Avoid paying for data that you don&#39;t need by restricting the set      // of place fields that are returned to just the address components.         autocomplete.setFields([&#39;name&#39;, &#39;formatted_address&#39;, &#39;geometry&#39;,          &#39;address_components&#39;]);                                                      // When the user selects an address from the drop-down, populate the       // address fields in the form.                        autocomplete.addListener(&#39;place_changed&#39;, () =&gt; {                                               //get the selected location result                                             let place = autocomplete.getPlace();                                                                });                                                                    document.getElementById(&quot;autocomplete-container&quot;).innerHTML = &quot;&quot;; document.getElementById(&quot;autocomplete-container&quot;).appendChild(node);</pre><p>Note That In AppComponent template file div with id ‘autocomplete-container’ is present. So there autocomplte map input will get apend. Here we are disabling defaultUI control like road type control And just enabling zoomControl.</p><p>*Maps Embed</p><pre>let node = document.createElement(“div”);                               document.getElementById(“mapEle”).innerHTML = “”;                                   node.style.height = “400px”;                                                              this.map = new google.maps.Map(node, {                                   <br>center: new google.maps.LatLng(20.5937, 78.9629),                                                                 zoom: 15,                                                                                      mapTypeId: google.maps.MapTypeId.ROADMAP,                                                  disableDefaultUI :true,                                                                       zoomControl: true});                                                              document.getElementById(“mapEle”).appendChild(node);                         </pre><p>By Using The Above Code Snap Within the OnInit lifecycle hook embed Map UI . And We will add one Drag able Marker Which Pick A location point coordinates on drag marker.</p><p>*Drag able Marker Embed</p><pre>var marker = new google.maps.Marker({                                          <br>position: myCenter,draggable: true,                  animation:google.maps.Animation.DROP,                                                            title:&#39;Point Your Location&#39;});                                                          this.markers.push(marker);                                                                    marker.setMap(this.map);                                                                    google.maps.event.addListener(marker, &#39;dragend&#39;, () =&gt; {                 document.getElementById(&quot;autocResult&quot;).innerHTML = &#39;Please Wait !!   Loading Address...&#39;;                                                                                           let poc = marker.getPosition();                                                                //this.geoCodeLatLng(new                          //google.maps.LatLng(poc.lat(),poc.lng()));});                                   </pre><p>Here For Drag able Marker We will get Latitude And Longitude. By using This we can fetch Address Of A Location. And By Typing in autocomplete field we will get Address Details of the searched location.</p><p><strong><em>Step 8: Run the application</em></strong></p><p>Start the application! Run command</p><pre>ng serve</pre><p>Do you see a map with autocomplete and drag able marker ?</p><blockquote><strong><em>I hope this was helpful!</em></strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13ca2604a3bd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>