如何借鉴谷歌地图在android系统的动态行驶路径路径、地图、动态、系统

由网友(┾演繹ヾ舊傷)分享简介:我已经集成在Android的谷歌地图。而我得到使用GPS当前位置。在Onlocationchanged我更新的当前位置。     我怀疑是我对谷歌地图的用户界面。我想走路或者从我的当前位置开车的时间为出发点,我要开始绘制在地图上的线路动态。     我搜索的净长的时间,但我没有得到任何解决方案。这里是我的code请谁能...

我已经集成在Android的谷歌地图。而我得到使用GPS当前位置。在Onlocationchanged我更新的当前位置。

    

我怀疑是我对谷歌地图的用户界面。我想走路或者从我的当前位置开车的时间为出发点,我要开始绘制在地图上的线路动态。

    

我搜索的净长的时间,但我没有得到任何解决方案。这里是我的code请谁能帮助我过度来到这个问题。

 私人无效initalizeMap(){     //谷歌播放服务提供           从片段//获取GoogleMap对象            使用GoogleMap =((SupportMapFragment)getChildFragmentManager()findFragmentById(R.id.map)。)的GetMap();            如果(gps.canGetLocation())            {                  双纬度= Double.valueOf(Helper.loadSaved preferences(getActivity(),NameConversion.LATITUDE));                  双东经= Double.valueOf(Helper.loadSaved preferences(getActivity(),NameConversion.LONGITUDE));                  Log.d(让GPS的价值,+纬度);                  Log.d(渐GPS龙,+经度);                //创建当前位置的经纬度对象                经纬度的latLng =新的经纬度(纬度,经度);                //创建标记                标记=新的MarkerOptions()位置(的latLng).title伪(你在这里!);                //更改标记图标                //设置你的图标点击这里                marker.icon(BitmapDesc​​riptorFactory.fromResource(R.drawable.marker_green_point));                //在谷歌地图显示的当前位置                googleMap.setTrafficEnabled(真);                googleMap.moveCamera(CameraUpdateFactory.newLatLng(的latLng));                //放大的谷歌地图                googleMap.animateCamera(CameraUpdateFactory.zoomTo(25));                googleMap.addMarker(标记);            }其他{                Toast.makeText(getActivity(),未能获得位置,Toast.LENGTH_SHORT).show();            }    }    @覆盖公共无效onLocationChanged(地点){        双纬度= gps.getLatitude();        //获取当前位置的经度        双经度= gps.getLongitude();        //创建当前位置的经纬度对象        Log.d(北纬地图类,纬度:+ gps.getLatitude());        Log.d(经度地图类,经度:+ gps.getLongitude());        经纬度的latLng =新的经纬度(纬度,经度);        //创建标记        的MarkerOptions标记=新的MarkerOptions()位置(的latLng).title伪(你在这里!);        //更改标记图标        //设置你的图标点击这里        marker.icon(BitmapDesc​​riptorFactory.fromResource(R.drawable.marker_green_point));        //在谷歌地图显示的当前位置        googleMap.moveCamera(CameraUpdateFactory.newLatLng(的latLng));        //放大的谷歌地图        googleMap.animateCamera(CameraUpdateFactory.zoomTo(25));} 

  

和我试着用以下链接[1日lnikn的第二个链接

解决方案 案例 如何鼓励游客走更多的路

为了获得在谷歌驱动器或步行时间映射,你必须使用谷歌提供的API方向的的。 API调用的方向会会是这样的:

http://maps.googleapis.com/maps/api/directions/json?origin=Chicago,IL&destination=Los%20Angeles,CA&sensor=false

,并且可以将一个类的内部,你会使得使用AsyncTask的HTTP调用这将是这样的:

  GenericUrl URL =新GenericUrl(http://maps.googleapis.com/maps/api/directions/json);url.put(原产地,产地来源);url.put(目的地,目的地);url.put(传感器,FALSE); 

请按照此教程或的这个为了获得方向API(包括驾车,公交,步行和骑自行车在地图上,方向。)

希望这将帮助!

i have integrated google map in android. and i am getting current location using GPS. on Onlocationchanged i am updating the current location.

My doubt is i am on the Google map UI . i wants to walk or drive that time from my current location as starting point and i wants to start draw the line on map dynamically.

i searched on net for long time but i am not getting any solution . here is my code please anyone help me to over come this problem.

private void initalizeMap()
{
     // Google Play Services are available
           // Getting GoogleMap object from the fragment
            googleMap = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)).getMap();

            if(gps.canGetLocation())
            {
                  double latitude = Double.valueOf(Helper.loadSavedPreferences(getActivity(), NameConversion.LATITUDE));
                  double longtitude = Double.valueOf(Helper.loadSavedPreferences(getActivity(), NameConversion.LONGITUDE));

                  Log.d("getting gps value", ""+ latitude);
                  Log.d("getting gps Long", ""+ longtitude);
                // Creating a LatLng object for the current location
                LatLng latLng = new LatLng(latitude, longtitude);
                // create marker
                marker = new MarkerOptions().position(latLng).title("You are here!");
                // Changing marker icon
                // set yours icon here
                marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_green_point));
                // Showing the current location in Google Map
                googleMap.setTrafficEnabled(true);
                googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
                // Zoom in the Google Map
                googleMap.animateCamera(CameraUpdateFactory.zoomTo(25));
                googleMap.addMarker(marker);
            }else{
                Toast.makeText(getActivity(), "failed To get the location", Toast.LENGTH_SHORT).show();
            }
    }

    @Override
public void onLocationChanged(Location location) {

        double latitude = gps.getLatitude();
        // Getting longitude of the current location
        double longitude = gps.getLongitude();
        // Creating a LatLng object for the current location

        Log.d("latitude map Class", "latitude:  " + gps.getLatitude());
        Log.d("longitude Map CLass", "longitude:  " + gps.getLongitude());

        LatLng latLng = new LatLng(latitude, longitude);
        // create marker
        MarkerOptions marker = new MarkerOptions().position(latLng).title("You are here!");
        // Changing marker icon
        // set yours icon here
        marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_green_point));
        // Showing the current location in Google Map
        googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
        // Zoom in the Google Map
        googleMap.animateCamera(CameraUpdateFactory.zoomTo(25));

}

and i tried with following links [1 st lnikn second link

解决方案

In order to get the drive or walking time on Google maps you have to make use of the Direction API's provided by Google. The API call for the Direction would would something like this:

http://maps.googleapis.com/maps/api/directions/json?origin=Chicago,IL&destination=Los%20Angeles,CA&sensor=false

And you can embed that inside a class where you would make an http call using AsyncTask which would look like this:

GenericUrl url = new GenericUrl("http://maps.googleapis.com/maps/api/directions/json");
url.put("origin", origin);
url.put("destination", destination);
url.put("sensor",false);

Please follow this tutorial or this in order get the direction API (that includes driving, transit. walking and bicycling direction on your maps. )

Hope that would help!!!

阅读全文

相关推荐

最新文章