2017-03-07 15 views
4

私は現在、Google Mapsを使ったAngular2プロジェクトを開発中です。角2 Google Maps with Multiple Markers

私は、マーカーとその周辺に複数のマーカーを表示しようとしています。 私はマップが機能していますが、マーカーに見えません。

<div class="google-maps"></div> 



constructor(private _elementRef:ElementRef) { 
    } 
    ngAfterViewInit() { 
    let el = this._elementRef.nativeElement.querySelector('.google-maps'); 
    GoogleMapsLoader.load((google) => { 
     let myLatlng = new google.maps.LatLng(44.5403,-78.5463); 
     new google.maps.Map(el, { 
     center: new google.maps.LatLng(44.5403, -78.5463), 
     zoom: 8, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 

     }); 
     new google.maps.Marker(el,{ 
     draggable: true, 
     animation: google.maps.Animation.DROP, 
      position: myLatlng, 
      title:"Hello World!" 
      }); 
     }); 
    } 
+0

このコードを試してみてください? –

+0

このリンクはあなたに役立ちます。http://stackoverflow.com/questions/3059044/google-maps-js-api-v3-simple-multiple-marker-example –

+0

エラーログマッサージなし – sridharan

答えて

0

マーカー機能が公式ドキュメントhereと一致していないようです。

let map = new google.maps.Map(el, { 
     center: new google.maps.LatLng(44.5403, -78.5463), 
     zoom: 8, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 

     }); 
let marker = new google.maps.Marker({ 
     draggable: true, 
     animation: google.maps.Animation.DROP, 
      position: myLatlng, 
      map: map,//set map created here 
      title:"Hello World!" 
      }); 
+0

複数のマーカーを追加するように感謝します – sridharan

+0

異なる 'position'と 'title'値で同じ'新しいマーカー 'を呼び出すことができます同じマップ..マーカーを作成し、必要なときにいつでも呼び出す機能があります。 –

+0

@surajこんにちは、割り当てられたコンテンツでマーカーに情報ウィンドウを追加する方法を知っていますか? [link](https://stackoverflow.com/questions/45252867/ionic-2-angular-2-adding-array-of-markers-with-infowindow-on-google-map) – aaa

2

何らかのエラーが記録され、これが私のプロジェクトの作業

Googleの公式ドキュメントhere

import GoogleMapsLoader from 'google-maps'; 
import { google } from 'google-maps'; 

ngAfterViewInit() { 

let el = this._elementRef.nativeElement.querySelector('.contact-us'); 

GoogleMapsLoader.KEY = 'g4554645645645645645646'; 

GoogleMapsLoader.load((google) => { 

let myLatlng = new google.maps.LatLng(23.5454, 90.8785); 

let map = new google.maps.Map(el, { 

    center: new google.maps.LatLng(23.8787878, 90.87878), 

    zoom: 18, 

    mapTypeId: google.maps.MapTypeId.ROADMAP 
    }); 

let marker = new google.maps.Marker({ 
     draggable: true, 
     animation: google.maps.Animation.DROP, 
     position: myLatlng, 
     map: map, 
     title:"Hello World!" 
    }); 

}); 

Template.html

<div class="contact-us" style="position: relative; height: 470px;"></div> 
+0

ちょっとアドバイスをしないでくださいSOのような公開サイトの任意の種類のAPIキー –