在Google Maps API中获取标记的坐标 [英] Getting coordinates of marker in Google Maps API

查看:442
本文介绍了在Google Maps API中获取标记的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Maps API。我使用下面的代码来获取标记的坐标。

  var lat = homeMarker.getPosition()。$一个; 
var lng = homeMarker.getPosition()。ab;

使用Google地图制作的应用程序一切正常。
但是我今天测试了它,并且得到正确坐标的问题。只有发现上面的代码变得未定义。在我console.log(homeMarker.getPosition())后,我发现这是现在他们用于坐标的变量。

  var lat = homeMarker.getPosition()。ab; 
var lng = homeMarker.getPosition()。cb;

我不会问为什么Google地图会这样做,但您也可以将其包含在您的答案中。我的问题是,如何在不改变我的代码的情况下正确地获取坐标,而Google地图每次更改他们正在使用的变量时都是如此。

pre> var lat = homeMarker.getPosition()。lat();
var lng = homeMarker.getPosition()。lng();

请参阅 google.maps.LatLng docs和 google.maps.Marker getPosition()


I'm using Google Maps API. And I'm using the code below to get the coordinates of the marker.

var lat = homeMarker.getPosition().$a;
var lng = homeMarker.getPosition().ab;

Everything is working fine with the app that I built using Google Maps. But I tested it today and I got problems getting the correct coordinates. Only to discover that the code above is getting undefined. After I console.log(homeMarker.getPosition()) I discovered that this is now the variables that they used for the coordinates.

var lat = homeMarker.getPosition().ab;
var lng = homeMarker.getPosition().cb;

I won't ask why Google Maps acts this way but you can also include it in your answer. My question is that how do I properly get the coordinates without changing my code everytime google maps changes the variables that they're using.

解决方案

var lat = homeMarker.getPosition().lat();
var lng = homeMarker.getPosition().lng();

See the google.maps.LatLng docs and google.maps.Marker getPosition().

这篇关于在Google Maps API中获取标记的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆