我的应用程序中有一个活动,其中有我用作地图的图像.如果图像与Google地图"网格对齐",那么当我使用地图的左上角和右下角时,我会从googlemaps在线获取,然后我可以将用户gps转换为屏幕上的x和y.但是,如果地图不是"网格对齐"并且与我的数学返回值成一定角度,则会将用户位置偏离屏幕.显然,我错过了关于如何处理地图角度的部分,所以如果有人能够阐明如何做到这一点,那将是非常有帮助的.
我知道我必须以弧度计算角度并进行一些转换,但我不知道从哪里开始.这是我用来获得x和y到目前为止在画布上绘图的方法.
public double[] getPositionGPS(Location upperLeft, Location lowerRight, Location current){
try{
double hypotenuse = upperLeft.distanceTo(current);
double bearing = upperLeft.bearingTo(current);
double currentDistanceY = Math.cos(bearing * Math.PI / OneEightyDeg) * hypotenuse;
// "percentage to mark the position"
double totalHypotenuse = upperLeft.distanceTo(lowerRight);
double totalDistanceY = totalHypotenuse * Math.cos(upperLeft.bearingTo(lowerRight) * Math.PI / OneEightyDeg);
double currentPixelY = currentDistanceY / totalDistanceY * ImageSizeH;
double hypotenuse2 = upperLeft.distanceTo(current);
double bearing2 = upperLeft.bearingTo(current);
double currentDistanceX = Math.sin(bearing2 * Math.PI / OneEightyDeg) * hypotenuse2;
// "percentage to mark the …Run Code Online (Sandbox Code Playgroud) 当我在设备上加载谷歌地图时,我有时会收到下面的屏幕.如第二次加载,如下所示.
否则它完全像正常的谷歌地图与路线我使用SupportmapFragment并获得googleMap对象.
supportMapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map_view_fragment);
Run Code Online (Sandbox Code Playgroud)
下面是在activity/fragment中显示map的代码
public static void drawRouteIntoMap(final List<? extends MapHelper> position, final GoogleMap googleMap) {
/*List<MapHelper> position = new ArrayList<MapHelper>();
for (int i = lastPosition; i < maps.size(); i++) {
position.add(maps.get(i));
}*/
final LatLngBounds.Builder mapBounds = new LatLngBounds.Builder();
if (position.size() > 0 && Validator.isNotNull(googleMap)) {
googleMap.clear();
List<PolylineOptions> polylineOptionses = new ArrayList<PolylineOptions>();
PolylineOptions option = null;
Boolean lastPause = null;
for (MapHelper map : position) {
if (map.isPause()) {
if (Validator.isNull(lastPause) || !lastPause) {
option = new …Run Code Online (Sandbox Code Playgroud) android google-maps google-maps-markers google-maps-android-api-2