标记旋转后的Android Google Map InfoWindow定位点 [英] Android Google Map InfoWindow anchor point after marker rotation

查看:496
本文介绍了标记旋转后的Android Google Map InfoWindow定位点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标记旋转后,如何重置标记的InfoWindows定位点始终位于顶部中间位置?

  static final LatLng PERTH = new LatLng(-31.90,115.86)这个问题是锚点随标记一起旋转。 ; 
Marker marker = mMap.addMarker(new MarkerOptions()
.position(PERTH)
.anchor(0.5,0.5)
.rotation(90.0)
.infoWindowAnchor (0.5,0));

//用新数据更新标记(位置和方向角)
var angle = 130.0;
marker.setPosition(new LatLng(-30.20,113.27));
marker.setRotation(angle);
marker.setInfoWindowAnchor(x,y); //如何计算这些值?

解决方案

  var angle = 130.0; 
var x = Math.sin(-angle * Math.PI / 180)* 0.5 + 0.5;
var y = - (Math.cos(-angle * Math.PI / 180)* 0.5 - 0.5);
marker.setInfoWindowAnchor((float)x,(float)y);

解释:

如果我们假设地图标记是圆形的(对于旋转目的最合理),并且我们知道InfoWindow定位点(B)可以设置为从0.0,0.0(左上角)到1,1(右下角)的任何相对坐标点,我们可以找到使用SIN和COS公式给定旋转度的任意点。 rel =noreferrer>


X与A之间的距离= B =半径* SIN(度);
A与B之间的距离=半径* COS(度);

通过Android标记坐标获取它们:



var x = Math.sin(-angle * Math.PI / 180)* 0.5 + 0.5;


  1. 我们发现SINE从反转旋转角度(负值)转换
    为弧度(度* PI / 180);
  2. >
  3. 乘以圆弧半径(0.5)以获得X轴上的距离;
  4. 按半径(+0.5)切换到右侧以在形状中间在X轴上);

var y = - (Math.cos(-angle * Math.PI / 180)* 0.5 - 0.5);


  1. 从oposit旋转角度值)转换为
    弧度(degree * PI / 180);
  2. 乘以圆弧半径(0.5)得到Y轴上的距离;
  3. 按半径(-0.5)向上移动以在形状的顶部(在Y轴上);
  4. 使值为正(带 - 符号)作为标记坐标系具有位置Y轴向下的值;


How to reset marker's InfoWindows anchor point after marker has been rotated to be always in top middle? The problem is that the anchor point is rotated along with marker.

static final LatLng PERTH = new LatLng(-31.90, 115.86);
Marker marker = mMap.addMarker(new MarkerOptions()
                    .position(PERTH)
                    .anchor(0.5,0.5)
                    .rotation(90.0)
                    .infoWindowAnchor(0.5,0));

//Update marker with new data (position and direction angle)
var angle = 130.0;
marker.setPosition(new LatLng(-30.20, 113.27)); 
marker.setRotation(angle); 
marker.setInfoWindowAnchor(x,y); // how to calculate these values?

解决方案

var angle = 130.0;
var x = Math.sin(-angle * Math.PI / 180) * 0.5 + 0.5;
var y = -(Math.cos(-angle * Math.PI / 180) * 0.5 - 0.5);
marker.setInfoWindowAnchor((float)x, (float)y);

Explanation:

If we assume that map marker is circular shape (most reasonable for rotation purpose) and as we know that InfoWindow anchor point (B) can be set to any relative coordinate point from 0.0,0.0 (upper left) to 1,1 (lower right) we can find any point on circle line by given rotation degree using SIN and COS formulas.

X distance between A and B = Radius * SIN(degree); Y distance between A and B = Radius * COS(degree);

Adopting them for Android marker coordinates we get:

var x = Math.sin(-angle * Math.PI / 180) * 0.5 + 0.5;

  1. We find SINE from oposit rotation angle (negative value) converted to radians (degree * PI/180);
  2. Multiply by circle radius(0.5) to get distance on X axis;
  3. Shift to RIGHT by radius(+0.5) to be in the middle of shape (on X axis);

var y = -(Math.cos(-angle * Math.PI / 180) * 0.5 - 0.5);

  1. Find COSINE from oposit rotation angle (negative value) converted to radians (degree * PI/180);
  2. Multiply by circle radius(0.5) to get distance on Y axis;
  3. Shift UP by radius(-0.5) to be on the top of shape (on Y axis);
  4. Make value positive(with - sign) as marker coordinate system has positive values on Y axis downwards;

这篇关于标记旋转后的Android Google Map InfoWindow定位点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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