希望暴露获取当前位置的属性
unionTime opened this issue · 4 comments
unionTime commented
希望暴露获取原生对象,的入口函数。如react-amap的events属性
想通过该插件获取中心点点位置
getCurrentPosition(callback:function(status,result){})
ct535101351 commented
嗯嗯,谢谢您,我试试!
ct535101351 commented
谢谢您,通过您的方法搞定了!
hsir05 commented
你好,如何获取当前德位置信息
csjiabin commented
看完源码我找到的方法,实测有效
@hsir05 @
import { Map as Amap } from 'react-amap';
import Geolocation from 'react-amap-plugin-geolocation';
// 官方源码
triggerCreated(props) {
const events = props.events || {};
if (('created' in events) && (typeof events.created === 'function')) {
events.created(this.geolocation);
}
}
...
const geolocationProps = {
buttonPosition: 'RB',
timeout: 10000,
events: {
created: o => {
// 获取用户当前的精确位置信息
o.getCurrentPosition((status, result) => {
if (result && result.position) {
console.log(result);
}
})
}
}
}
....
<Amap {...amapProps}>
<Geolocation {...geolocationProps} />
</Amap>