使用Google地图API映射和移动标记 [英] Map and Moving Marker using Google Maps API

查看:178
本文介绍了使用Google地图API映射和移动标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须编写一个演示程序,它应该像在Flight中移动地图那样,并且需要在两个之间绘制相同的曲线 Polyline geo points / locations ,您可以在下面的图片中看到



甚至,我也不介意将切换到其他SDK,比如 Mapbox SDK (如果你中的某个人可以真的帮我获得我实际需要的东西)



要在两点之间绘制折线,我正在使用:

  private void polyLine(){

LatLng starting = new LatLng(##。######,##。#### ##);
LatLng ending = new LatLng(##。######,##。######);

PolylineOptions line = new PolylineOptions()。add(starting,ending);

mGoogleMap.addMarker(new MarkerOptions()。position(starting).title(Start));
mGoogleMap.addMarker(new MarkerOptions()。position(ending).title(End));

mGoogleMap.addPolyline(line);

$ b

更新位置和动画标记,我正在使用:

  @Override 
public void onLocationChanged(Location location)
{
Toast.makeText(this,Location Changed+ location.getLatitude()
+ location.getLongitude(),Toast.LENGTH_LONG).show();

mLastLocation = location;

if(mCurrLocationMarker!= null){
mCurrLocationMarker.remove();
}

LatLng latLng = new LatLng(location.getLatitude(),location.getLongitude());

if(ourGlobalMarker == null){//首次添加标记来映射
ourGlobalMarker = mGoogleMap.addMarker(new MarkerOptions()。position(latLng)
.icon( BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ROSE)));
MarkerAnimation.animateMarkerToICS(ourGlobalMarker,latLng,new LatLngInterpolator.Spherical());
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng,18));
} else {
MarkerAnimation.animateMarkerToICS(ourGlobalMarker,latLng,new LatLngInterpolator.Spherical());
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng,18));
}

}

我的要求:



POLYLINE

  1。我必须创建一个Polyline,您可以在附加图像(曲线图)中看到相同的

1.1。虚线弯曲(如果地区尚未开始)

1.2。经常弯曲(在已经覆盖的区域)

CURRENT MARKER

  2。显示Polyline右侧的当前位置标记

(而我想在Polyline路径上显示Animate标记)


解决方案

对于Polyline谷歌地图使用PolylineOptions


  1. z-index

  2. pattern()添加短划线项目


I have to write a demo, that should work like Moving Map within Flight and need to draw same curved Polyline between two geo points / locations as you can see in below image.

Even, I would not mind switching to some other SDK like Mapbox SDK (If someone of you can really help me in getting What I need actually)

To draw a Polyline between two points, I am using:

   private void polyLine() {

        LatLng starting = new LatLng(##.######, ##.######);
        LatLng ending = new LatLng(##.######, ##.######);

        PolylineOptions line = new PolylineOptions().add(starting, ending);

        mGoogleMap.addMarker(new MarkerOptions().position(starting).title("Start"));
        mGoogleMap.addMarker(new MarkerOptions().position(ending).title("End"));

        mGoogleMap.addPolyline(line);

    }

To Update Location and Animate Marker, I am using:

@Override
    public void onLocationChanged(Location location)
    {
        Toast.makeText(this, "Location Changed " + location.getLatitude()
                + location.getLongitude(), Toast.LENGTH_LONG).show();

        mLastLocation = location;

        if (mCurrLocationMarker != null) {
            mCurrLocationMarker.remove();
        }

        LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());

        if(ourGlobalMarker == null) { // First time adding marker to map
            ourGlobalMarker = mGoogleMap.addMarker(new MarkerOptions().position(latLng)
                    .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ROSE)));
            MarkerAnimation.animateMarkerToICS(ourGlobalMarker, latLng, new LatLngInterpolator.Spherical());
            mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 18));
        } else {
            MarkerAnimation.animateMarkerToICS(ourGlobalMarker, latLng, new LatLngInterpolator.Spherical());
            mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 18));
        }

    }

My Requirements:

POLYLINE

1. I have to create a Polyline the same you can see in attached image (curved one) 

1.1. Dotted curved (if area not started yet)

1.2. Regular curved (in case area already covered)

CURRENT MARKER

2. Showing current Location marker at right side of Polyline 

(whereas, I want to show Animate marker on Polyline path)

解决方案

For Polyline google map use PolylineOptions

  1. curved line use z-index
  2. pattern() add dash item

这篇关于使用Google地图API映射和移动标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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