質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Google マップ

Google Mapは、Google社がオンラインで提供している地図・ローカル検索サービスです。GIS(Geographic Information System:地理情報システム)の中の「WebGIS」に該当します。地図・航空写真・地形の表示方式があり、それぞれユーザーが縮尺を調整して表示させることができます。地域の情報サービスを検索する機能やルート検索の機能も搭載されています。

Q&A

0回答

1870閲覧

【Angular2】GoogleMapAPIを使ってAutoCompleteをしたい

KoheiOkazaki

総合スコア43

Google マップ

Google Mapは、Google社がオンラインで提供している地図・ローカル検索サービスです。GIS(Geographic Information System:地理情報システム)の中の「WebGIS」に該当します。地図・航空写真・地形の表示方式があり、それぞれユーザーが縮尺を調整して表示させることができます。地域の情報サービスを検索する機能やルート検索の機能も搭載されています。

0グッド

0クリップ

投稿2016/11/23 17:33

こんにちは。Anguarjs2とonsenUI2を使ってハイブリッドアプリを作成しているのですが、Angularjs2のGoogleMapAPIを使ってAutoCompleteをしたいと思っています。

以下コード全容です

import { Component, NgModule, OnInit, ViewChild, ElementRef } from '@angular/core'; import { FormControl, FormsModule, ReactiveFormsModule } from "@angular/forms"; import { BrowserModule } from "@angular/platform-browser"; import { AgmCoreModule, MapsAPILoader } from 'angular2-google-maps/core'; // import {GoogleplaceDirective} from '../googleplace.directive'; import {NgModel} from '@angular/forms'; @Component({ selector: 'app-root', styles: [` .sebm-google-map-container { height: 300px; } `], template: ` <google-search-bar></google-search-bar> <div class="container"> <div class="form-group"> <input placeholder="search for location" autocorrect="off" autocapitalize="off" spellcheck="off" type="text" class="form-control" #search [formControl]="searchControl"> </div> <sebm-google-map [latitude]="latitude" [longitude]="longitude" [scrollwheel]="false" [zoom]="zoom"> <sebm-google-map-marker [latitude]="latitude" [longitude]="longitude"></sebm-google-map-marker> </sebm-google-map> </div> ` }) export class GoogleMap implements OnInit { public latitude: number; public longitude: number; public searchControl: FormControl; public zoom: number; public fuzzyControl: FormControl; public address:string; @ViewChild("search") public searchElementRef: ElementRef; constructor( private mapsAPILoader: MapsAPILoader ) {} ngOnInit() { //set google maps defaults this.zoom = 4; this.latitude = 39.8282; this.longitude = -98.5795; //create search FormControl this.searchControl = new FormControl(); this.fuzzyControl = new FormControl(); //set current position this.setCurrentPosition(); this.setMapsAPILoader(); //load Places Autocomplete this.mapsAPILoader.load().then(() => { let autocomplete = new google.maps.places.Autocomplete(this.searchElementRef.nativeElement, { types: ["address"] }); autocomplete.addListener("place_changed", () => { //get the place result let place: google.maps.places.PlaceResult = autocomplete.getPlace(); //set latitude and longitude this.latitude = place.geometry.location.lat(); this.longitude = place.geometry.location.lng(); }); }); } private setCurrentPosition() { if ("geolocation" in navigator) { navigator.geolocation.getCurrentPosition((position) => { this.latitude = position.coords.latitude; this.longitude = position.coords.longitude; this.zoom = 12; }); } }

エラー文です。AutoCompleteのプロパティがないと言われています。

Unhandled Promise rejection: Cannot read property 'Autocomplete' of undefined ; Zone: angular ; Task: Promise.then ; Value: TypeError: Cannot read property 'Autocomplete' of undefined(…) TypeError: Cannot read property 'Autocomplete' of undefined

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問