我在学习反应打字稿。我使用的反应谷歌地图显示我的地区。我成功地展示了这张地图。当我试图使用标记从反应-谷歌地图指出我的地区和定位我的纬度和经度。我收到打字错误:Property 'position' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<GoogleMapReact> & Readonly<Props> & Readonly<...>。我真的不知道怎么解决它。
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import ErrorBoundary from 'components/errorBoundary';
import GoogleMapReact from 'google-map-react';
import Marker from 'google-map-react'
export interface ITestNewListProps {
className?: string;
position?: { lat: number; lng: number; };
}
const TestMaps = ({ className, position }: ITestNewListProps) => {
const [state, setstate] = useState(
{
center: {
lat: 60.1098678,
lng: 24.7385084
},
zoom: 7
}
)
return (
<ErrorBoundary id="TestNewListErrorBoundary">
<div className={`${className}`}>
<div style={{ height: '100vh', width: '100%' }}>
<GoogleMapReact
bootstrapURLKeys={{ key: "*************************" }}
defaultCenter={state.center}
defaultZoom={state.zoom}
>
<Marker position={{ lat: 60.1098678, lng: 24.7385084 }} />//Geting error from here
</GoogleMapReact>
</div>
</div>
</ErrorBoundary>
);
};
TestMaps.displayName = `test`;
export default styled(TestMaps)`
`;发布于 2020-05-08 13:04:35
请记住,google-map-react允许您在映射中呈现任何反应组件。
库不导出Marker组件。
但是,如果您想使用默认的Google标记,您可以看到一个解决方案here。
根据文档中的示例,您应该能够通过定义自己的标记组件来实现这样的目标:
import React, { Component } from 'react';
import GoogleMapReact from 'google-map-react';
const Marker = ({ text }) => <div>{text}</div>;
class SimpleMap extends Component {
static defaultProps = {
center: {
lat: 59.95,
lng: 30.33
},
zoom: 11
};
render() {
return (
<div style={{ height: '100vh', width: '100%' }}>
<GoogleMapReact
bootstrapURLKeys={{ key: /* YOUR KEY HERE */ }}
defaultCenter={this.props.center}
defaultZoom={this.props.zoom}
>
<Marker
lat={59.955413}
lng={30.337844}
text="My Marker"
/>
</GoogleMapReact>
</div>
);
}
}
export default SimpleMap;发布于 2020-12-23 14:41:24
Mac: sudo npm install @ionic-native/geolocation@5.27.0
window:npm install @ionic-native/geolocation@5.27.0https://stackoverflow.com/questions/61679036
复制相似问题