2

I have a requirement to integrate google location dropdown(auto complete) for address search on textbox and plot a route on the map using angular 2 beta version and typescript.

I have searched for the compatible library. but cant find the one.

Can anyone please suggest me the library/component for google location search and maps in angular 2.

2 Answers 2

1

There is no google location search with typescript for Angular 2

You have to import the Google Places javascript api as a module into your Angular 2 application

Sign up to request clarification or add additional context in comments.

Comments

1

For google location search with Angular2 typescript, you can use angular2-google-map-auto-complete library.

Step1: Run following command, it will give you angular2-google-map-auto-complete package-

npm install angular2-google-map-auto-complete

Step2: Sample component looks like this-

import { Component } from '@angular/core';
import {GoogleplaceDirective} from './googleplace.directive';

@Component({
  selector: 'my-app',
  directives: [GoogleplaceDirective],
  template: `<h1>My First Angular 2 App</h1>
  <input type="text" [(ngModel)] = "address"  (setAddress) = "getAddress($event)" googleplace/>
  `

})
export class AppComponent { 
  public address : Object;
       getAddress(place:Object) {       
           this.address = place['formatted_address'];
           var location = place['geometry']['location'];
           var lat =  location.lat();
           var lng = location.lng();
           console.log("Address Object", place);
       }
}

Step3: Add script tag in index.html

<script src="https://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>

Output result:

output result

See if this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.