Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <ion-row>
- <ion-item>
- <ion-label>Search</ion-label>
- <ion-input id="places" type="text" name="search"></ion-input>
- </ion-row>
- <div #map id="map"></div>
- export class HomePage {
- public latitude: number;
- public longitude: number;
- @ViewChild('map') mapElement;
- map: any;
- marker: any;
- search: string;
- constructor(public navCtrl: NavController, public platform: Platform) {
- /*platform.ready().then(() => {
- this.InitMap();
- });*/
- }
- ionViewDidLoad(){
- this.InitMap();
- }
- InitMap() {
- this.setLocation();
- let input = document.getElementById('places');
- let autocomplete = new google.maps.places.Autocomplete(input);
- google.maps.event.addListener(autocomplete, 'place_changed', () => {
- let place = autocomplete.getPlace();
- this.latitude = place.geometry.location.lat();
- this.longitude = place.geometry.location.lng();
- alert(this.latitude + ", " + this.longitude);
- console.log(place);
- });
- }
- setLocation() {
- let latLng = new google.maps.LatLng(53.550513, 9.994241);
- let mapOptions = {
- center: latLng,
- zoom: 15,
- mapTypeId: google.maps.MapTypeId.ROADMAP
- };
- this.map = new google.maps.Map(this.mapElement.nativeElement, mapOptions);
- this.marker = new google.maps.Marker({
- position: latLng,
- map: this.map,
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement