【问题标题】:GoogleMaps SDK Cordova distance in pixel?GoogleMaps SDK Cordova 距离(以像素为单位)?
【发布时间】:2016-11-06 10:41:45
【问题描述】:

我在科尔多瓦上使用谷歌地图 SDK。 我有屏幕左上角的 lat/lng 位置和像素屏幕中一个点的位置。 我想在 lat/lng 中找到这个点的位置。

为此,我想知道 lat 中 1px 和 lng 中 1px 根据缩放地图级别的转换。

你知道怎么做吗? 非常感谢。

更新代码:

    $("#icon").draggable({
             helper : 'clone',
        stop:function(event,ui) {
            var wrapper = $("#container-emote").offset();
            var borderLeft = parseInt($("#container-emote").css("border-left-width"),10);
            var borderTop = parseInt($("#container-emote").css("border-top-width"),10);
            var pos = ui.helper.offset();
            $scope.createEmote(pos.left - wrapper.left - borderLeft + 40, -(pos.top - wrapper.top - borderTop)+185,2 );
        }
        });

$scope.createEmote = function(a,b,c) {
                var height = screen.height;
                b = height - b;
                map.fromPointToLatLng([a, b], function (point) {
                alert('lat' + point[0] + ' lng:' + point[1]);
            });
        };

解决方案:

其实a和b在发射时是NaN,这里是最终的:

$scope.createEmote = function(a,b,c) {
                var height = screen.height;
                b = height - b;
                if (!isNaN(a) && !isNaN(b)){
                        map.fromPointToLatLng([a , b], function (point) {
                        console.log('mousedown lat' + point[0] + ' lng:' + point[1]);
                    });
                }
        };

【问题讨论】:

  • 您可以使用stackoverflow.com/questions/15007528/…处的代码将像素(点)坐标中的点转换为纬度/经度
  • 我只是发现我只需要将 a 和 b 转换为整数??
  • 当您记录 a、b、lat、lng 时,您会得到什么值?
  • a 是屏幕的 x 和屏幕的 y,以像素为单位。但我猜它们是字符串,我必须把它们放在整数或什么的?
  • 因为它在我执行 map.fromPointToLatLng([100, 100], function (point) { 但当我尝试将 var 转换为像 map.fromPointToLatLng([parseInt(a), parseInt(b)], 函数(点){

标签: cordova google-maps google-maps-api-3 google-maps-sdk-ios


【解决方案1】:

我认为这是我在 cmets 中链接到的先前问题的重复。但是,由于您使用的是 Cordova,因此会有所改变。

如果您使用的是this Cordova Google Maps plugin,请查看此处描述的fromPointToLatLng()

https://github.com/mapsplugin/cordova-plugin-googlemaps/wiki/Map

https://github.com/mapsplugin/cordova-plugin-googlemaps/wiki/Map.fromPointToLatLng

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多