2017-05-30 255 views
0

我想标记图标旋转道路方向,你可以在图片看到的只是刚放置,但它不是旋转到道路方向..我已经试过下面的代码就如何旋转谷歌地图标记,道路方向

double lat = 19.205681 
double lon = 72.871742 
loc.setLatitude(lat); 
loc.setLongitude(lon); 
Location newLoc = new Location("service Provider"); 
newLoc.setLongitude(lat); 
newLoc.setLongitude(lon); 
map.addMarker(new MarkerOptions() 
    .position(new LatLng(data.getLat(),data.getLon())) 
    .icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_pandu_car)) 
    .anchor(0.5f,0.5f) 
    .rotation(loc.bearingTo(newLoc)) 
    .flat(true)); 

注:标记有个别位置(ofcource)我不想显示来自后的位置轴承...只有个别标记面临道路方向

感谢您 enter image description here

更新:我想设定我的标记ER(汽车)这样的奥拉应用

enter image description here

+0

如果您是从API获取,上传结束必须提供轴承的服务器,使其返回到你。这是因为您不想根据当前位置设置方位,而是根据所提供位置的实际方位来设置方位。 – Milan

回答

0

我已经试过你的代码中,首先检查是newLoc的承压或不? 只是做了一些修改,如下图所示,你可以尝试一下:

LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, 
       new com.google.android.gms.location.LocationListener() { 
        @Override 
        public void onLocationChanged(Location location1) { 
         if (location1 != null) { 
          if (currentPositionMarker != null) { 
           currentPositionMarker.remove(); 
          } 
          double latitude = location1.getLatitude(); 
          double longitude = location1.getLongitude(); 
          LatLng latLng = new LatLng(latitude, longitude); 
          int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity); 
          if (status == ConnectionResult.SUCCESS) { 
           currentPositionMarker = googleMap.addMarker(new MarkerOptions().position(latLng) 
             .icon(BitmapDescriptorFactory.fromResource(R.drawable.current_position)) 
             .rotation(location1.getBearing()).flat(true).anchor(0.5f, 0.5f) 
             .alpha((float) 0.91)); 

          } else { 
           GooglePlayServicesUtil.getErrorDialog(status, activity, status); 
          } 
         } 
        } 
       }); 
+0

没有它不工作:(标志仍属于垂直的(而不是每路方向)..你可以请分享整个代码?或者你想我的全球化志愿服务青年 –

+0

更多的代码,看看我的编辑答案,可能它可以帮助你 – BSavaliya