2

我想制作一个应用程序来显示旅行时间和距离以及用户位置到目的地位置的路径。

这是我的 TampilkanMap 课程:

public class TampilkanMap extends FragmentActivity {
    GoogleMap googleMap;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map);

        SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);

        googleMap = fm.getMap();

        // Enabling MyLocation Layer of Google Map
        googleMap.setMyLocationEnabled(true);
        // lokasi wisata
        Marker GunungButtuKabombong = googleMap.addMarker(new MarkerOptions()
                .position(new LatLng(-3.568419, 119.777141)).title("Enrekang")
                .snippet("Gunung Buttu kabobong"));
        Marker HutanMalino = googleMap.addMarker(new MarkerOptions()
                .position(new LatLng(-5.296776, 119.740562)).title("Gowa")
                .snippet("Hutan Malino"));
        Marker SombaOpu = googleMap.addMarker(new MarkerOptions()
                .position(new LatLng(-5.191144, 119.407899)).title("Makassar")
                .snippet("Benteng Somba Opu"));
        Marker Londa = googleMap.addMarker(new MarkerOptions()
                .position(new LatLng(-2.968156, 119.900479)).title("Rantepao")
                .snippet("Londa"));
        Marker Jompie = googleMap.addMarker(new MarkerOptions()
                .position(new LatLng(-4.005563, 119.634331)).title("Parepare")
                .snippet("Hutan Jompie"));
        Marker Lumpue = googleMap.addMarker(new MarkerOptions()
                .position(new LatLng(-4.057233, 119.622411)).title("Parepare")
                .snippet("Pantai Lumpue"));
        Marker Bira = googleMap.addMarker(new MarkerOptions()
                .position(new LatLng(-5.550204, 120.206166)).title("Bulukumba")
                .snippet("Pantai Tanjung Bira"));
        Marker Losari = googleMap.addMarker(new MarkerOptions()
                .position(new LatLng(-5.133219, 119.41662)).title("Makassar")
                .snippet("Pantai Losari"));
        Marker Bantimurung = googleMap.addMarker(new MarkerOptions()
                .position(new LatLng(-5.006130, 119.650970)).title("Maros")
                .snippet("Air Terjun Bantimurung"));
        Marker Kelelawar = googleMap.addMarker(new MarkerOptions()
                .position(new LatLng(-4.349835, 119.927759)).title("Soppeng")
                .snippet("Kelelawar"));
        Marker DanauTempe = googleMap.addMarker(new MarkerOptions()
                .position(new LatLng(-4.110587, 119.953579)).title("Wajo")
                .snippet("Danau Tempe"));
        Marker FortRotterdam = googleMap.addMarker(new MarkerOptions()
                .position(new LatLng(-5.134148, 119.405276)).title("Makassar")
                .snippet("Benteng Fort Rotterdam"));
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.opt_menu, menu);
        return true;
    }

    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {
        case R.id.satelit:
            googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
            return true;

        case R.id.street:
            googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
            return true;

        default:
            return super.onOptionsItemSelected(item);
        }
    }
}

如果用户从我的位置触摸标记,我想制作一条路径,我该如何制作?

4

1 回答 1

0

我就是这样做的:我听说它只在美国有效,这正是我所听到的:步行、开车和骑自行车,在那里也可以分享到 facebook 和堆叠地图的方法,欢迎使用它,我认为有些进口是不必要的,但我还没有时间删除它们,而且我知道你的新产品如果你不表现出研究努力并使你的问题不那么模糊,它们会把你踢出去

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.Log;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class OverlayPoints extends ItemizedOverlay<OverlayItem>
{

private ArrayList<Drawable> mImage = new ArrayList<Drawable>();
 private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
 private ArrayList<File> filepic = new ArrayList<File>();

 private Context mContext;
 private boolean active;
 private boolean touch = false;


public OverlayPoints(Drawable defaultMarker, Context context) 
{
    super(boundCenterBottom(defaultMarker));
     mContext = context;
     active = false;

    // TODO Auto-generated constructor stub
}

 public void addOverlay(OverlayItem overlay, Drawable image,File pic)
 {
     active = true;

     filepic.add(pic);
 mOverlays.add(overlay);
 mImage.add(image);
 populate();

 }

@Override
protected OverlayItem createItem(int arg0) 
{
    return mOverlays.get(arg0);
    // TODO Auto-generated method stub

}
public void delete()
{

    mImage = new ArrayList<Drawable>();
    mOverlays = new ArrayList<OverlayItem>();
}

@Override
public int size() {
    // TODO Auto-generated method stub
     return mOverlays.size();
}
 protected boolean onTap(int index)
 {
 final OverlayItem item = mOverlays.get(index);
 final File file = filepic.get(index);
 AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
 dialog.setIcon(mImage.get(index));
 dialog.setTitle(item.getTitle());
 dialog.setMessage(item.getSnippet());
 dialog.setNegativeButton("Dismiss", new OnClickListener(){

    @Override
    public void onClick(DialogInterface arg0, int arg1) {
        // TODO Auto-generated method stub

    }

 });
 dialog.setNeutralButton("Set Course", new OnClickListener(){

    @Override
    public void onClick(DialogInterface dialog, int which) {
        // TODO Auto-generated method stub
        GeoPoint point = item.getPoint();
        final double lat = (double)point.getLatitudeE6()/ 1E6;
        final double lon = (double)point.getLongitudeE6()/ 1E6;

        AlertDialog.Builder course = new AlertDialog.Builder(mContext);
        course.setNegativeButton("On Foot", new OnClickListener(){


            @Override
            public void onClick(DialogInterface arg0, int arg1) {
                // TODO Auto-generated method stub
                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("google.navigation:ll=%s,%s%s", lat, lon, "&mode=w")));
                mContext.startActivity(i);
            } 

        });

        course.setNeutralButton("By Car", new OnClickListener(){

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("google.navigation:ll=%s,%s%s", lat, lon, "&mode=d")));
                mContext.startActivity(i);
            }

        });
        course.setPositiveButton("On Bike", new OnClickListener(){

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("google.navigation:ll=%s,%s%s", lat, lon, "&mode=b")));
                mContext.startActivity(i);
            }

        });
    course.show();  
    }

 });
 dialog.setPositiveButton("Share", new OnClickListener(){

    @Override
    public void onClick(DialogInterface dialog, int which) {
        // TODO Auto-generated method stub
        Uri uri = Uri.fromFile(file);
        Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);

        shareIntent.setType("image/png");
        shareIntent.putExtra(android.content.Intent.EXTRA_STREAM,
                        uri); //Share the image on Facebook
        PackageManager pm = mContext.getApplicationContext().getPackageManager();
        List<ResolveInfo> activityList = pm.queryIntentActivities(
                            shareIntent, 0);
        for (final ResolveInfo app : activityList) {
            if ((app.activityInfo.name).contains("facebook")) {
                final ActivityInfo activity = app.activityInfo;
                final ComponentName name = new ComponentName(
                            activity.applicationInfo.packageName,
                            activity.name);
                shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                    | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                shareIntent.setComponent(name);
                mContext.startActivity(shareIntent);
                break;
                    }
                }
    }

 });
 if(touch)
     dialog.show();
 return true;
 }
 public boolean isused()
 {
     return active;
 }
 public void showlogfalse(){
     touch = false;
 }
 public void showlogtrue(){
     touch = true;
 }

}

于 2013-03-29T01:21:00.013 回答