我正在尝试在angular.io
组件中实现google-maps
,它工作正常,除了infowindow
对象似乎没有实现属性。
你能不能请建议做错了什么?
外部导入
import { Component, OnInit } from '@angular/core';
import GoogleStyes from './google.styles';
import GoogleMap from 'google-maps';
组件
@Component({
selector: 'app-map',
template: '<div id="map"></div>',
styleUrls: ['./map.component.scss']
})
export class MapComponent implements OnInit {
constructor() { }
//------------------------------------
// Variables
//------------------------------------
map:object;
center:object = { lat: 41.378842, lng: 2.182331 };
marker:object;
infowindow:object;;
markerInfo:string = "<div>Hello</div>"
//------------------------------------
// Initializing Goolge Maps
//------------------------------------
ngOnInit() {
GoogleMap.load((google, infowindow) => {
this.map = new google.maps.Map(document.getElementById('map'), {
center: this.center,
});
this.infowindow = new google.maps.InfoWindow({
content: this.markerInfo
});
this.marker = new google.maps.Marker({
position: this.center,
map: this.map,
title: 'Hello World!'
});
google.maps.event.addListener(this.marker, 'click', () => {
infowindow.open(this.map, this.marker);
});
});
}
}
错误
polyfills.bundle.js:100455 Uncaught TypeError: Cannot read property 'open' of undefined
at _.Le.<anonymous> (main.bundle.js:1173)
at Object._.A.trigger (js?callback=__google_maps_api_provider_initializator__:102)
at DU.handleEvent (marker.js:50)
at ly._.k.de (map.js:46)
at ly._.k.Ki (map.js:44)
at Object._.A.trigger (js?callback=__google_maps_api_provider_initializator__:102)
at jq.<anonymous> (common.js:135)
at Object._.A.trigger (js?callback=__google_maps_api_provider_initializator__:102)
at jq._.k.Wi (common.js:197)
at HTMLDivElement.<anonymous> (js?callback=__google_maps_api_provider_initializator__:39)
答案 0 :(得分:1)
import re
import datetime
date = '1/1/2016 00:00'
m = re.search('^(\d{1,2})/(\d{1,2})/(\d{4})', date)
d = datetime.datetime(day=int(m.group(1)), month=int(m.group(2)), year=int(m.group(3)))
print d.weekday() # prints 4 = Friday
中没有infowindow
个对象,只有GoogleMap.load((google) => {...})
。
您已在此处定义了google
个对象
infowindow
只需使用它
this.infowindow = new google.maps.InfoWindow({
content: this.markerInfo
});
它应该按预期工作。