Javascript 当用户使用GoogleMapAPI将pin拖到任何地方时,如何获得用户的新lat、lang

Javascript 当用户使用GoogleMapAPI将pin拖到任何地方时,如何获得用户的新lat、lang,javascript,ember.js,ember-data,ember-cli,Javascript,Ember.js,Ember Data,Ember Cli,我正在构建一个web应用程序,它实际上允许用户查看所选地址的标记。此外,我正在尝试构建一个功能,当用户拖动pin时,它应该更新lat,lang值。虽然我能够使用下面的代码获得用户的当前位置,但最大的问题是当用户将pin拖到任何位置时,我如何获得用户的新lat、lang?非常感谢您的回复,谢谢。顺便说一句,我正在使用这个插件 /component.js getCurrentLocation() { if (navigator.geolocation) { con

我正在构建一个web应用程序,它实际上允许用户查看所选地址的标记。此外,我正在尝试构建一个功能,当用户拖动pin时,它应该更新lat,lang值。虽然我能够使用下面的代码获得用户的当前位置,但最大的问题是
当用户将pin拖到任何位置时,我如何获得用户的新lat、lang
?非常感谢您的回复,谢谢。顺便说一句,我正在使用这个插件

/component.js

    getCurrentLocation() {
      if (navigator.geolocation) {
        console.log(navigator.geolocation);
        navigator.geolocation.getCurrentPosition((position) => {
         this.set('selectedLatitude', position.coords.latitude);
         this.set('selectedLongitude', position.coords.longitude);
         this.set('hasSelectedFromAutoCompleteOrCurrentLocation', true);

         this.reverseGeoCode(position.coords.latitude, position.coords.longitude).then((resp) => {
           this.set('formattedAddress', resp);
         }).catch((error) => console.log(error));

       });
      } else {
        console.log("Your browser doesn't support geo location");
      }
    },
/template.hbs

    {{#g-map lat=cityLatitude lng=cityLongitude zoom=zoomValue options=mapOptions as |context|}}
      {{#if hasSelectedFromAutoCompleteOrCurrentLocation}}
        {{g-map-marker context lat=selectedLatitude lng=selectedLongitude onDrag=(action "getCurrentLocation") draggable=true zoom=zoomValue icon=myIcon}}
      {{/if}}
    {{/g-map}}

Ola@Mikelemuel,谢谢你的提问!我相信,
ondrag
会把职位信息传给你。(注意:我不知道
ember
)我已经在使用
onDrag
,它可以工作,但是
lat
lang
的值没有变化,可能存在
中心
属性或类似的东西?因此,文档
onDrag
应该接收
lat
lng
属性。如果您使用的是最新版本,它没有收到这些属性,我会认为它是一个bug,尝试使用Engor TundEdter或CODESDENBOX设置一个最小的复制,并将其作为一个发布报告。非常感谢您的详细解答!D:大拇指,问题是,
lat,lon
从哪里来?
updateLocation()
如何接收到它在某个地方没有定义的值?我试过了,效果很好,但我只是想知道它是从哪里来的。非常感谢。实际上,我们正在将一个函数传递到
onDrag
,这是谷歌地图API的一部分。在地图上拖动时,传递到onDrag的函数将使用新的Lat和Lon调用。这有意义吗?如果您想了解更多信息,可以查看google map API文档(与Ember无关)