GoogleMaps SDK Cordova 像素距离?
GoogleMaps SDK Cordova distance in pixel?
我在 cordova 上使用 google 地图 SDK。
我在屏幕左上角的 lat/lng 中有位置,在像素屏幕中有一个点的位置。
我想在lat/lng.
中找到这个点的位置
为此,我想知道 1px in lat 和 1px in lng 根据缩放地图级别的转换。
你知道怎么做吗?
非常感谢。
更新代码:
$("#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]);
});
}
};
我认为这是我在评论中链接到的先前问题的重复。但是,由于您使用的是 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
我在 cordova 上使用 google 地图 SDK。 我在屏幕左上角的 lat/lng 中有位置,在像素屏幕中有一个点的位置。 我想在lat/lng.
中找到这个点的位置为此,我想知道 1px in lat 和 1px in lng 根据缩放地图级别的转换。
你知道怎么做吗? 非常感谢。
更新代码:
$("#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]);
});
}
};
我认为这是我在评论中链接到的先前问题的重复。但是,由于您使用的是 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