获取错误TypeError:尝试将latlng对象分配给变量时,无法设置null错误的属性'userCoords'
Home.page.ts文件
export class HomePage {
map: GoogleMap;
userCoords : any ;
constructor() {
navigator.geolocation.getCurrentPosition
(this.geolocationSuccess,this.geolocationError,{});
this.loadMap();
}
loadMap() {
let mapOptions: GoogleMapOptions = {
'camera' : {
target: this.userCoords,
zoom: 15
},
'preferences': {
'zoom': {
'minZoom': 15,
'maxZoom': 18
}
}
this.map = GoogleMaps.create('map_canvas', mapOptions);
}
geolocationSuccess = function(position)
{
this.userCoords = {lat: position.coords.latitude,lng:
position.coords.longitude} /////===>getting error here
}
geolocationError = function()
{
}
}
如何将值lat和lng分配给另一个变量 我必须尝试将userCoords定义为object,String和任何
答案 0 :(得分:1)
问题在于函数是回调函数,而“ this”是当前函数上下文。使用指示的箭头功能自动将组件“ this”绑定到该功能
<cfoutput>
<input type="date" class="form-control" name="dtStart" value="#LSDateFormat(now(),'yyyy-mm-dd')#" required />
<br />
My Date: #LSDateFormat(now(), 'mm/dd/yyyy')#
</cfoutput>