绘制我的位置到制造商谷歌地图api v2之间的路线

时间:2015-01-14 15:26:17

标签: android google-maps google-maps-android-api-2

import android.graphics.Color; 
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.PolylineOptions;

public class AngleseaBuilding extends ActionBarActivity {

    private GoogleMap map;
    private final LatLng LOCATION_BURNABY = new LatLng (50.797879, -1.096553);
    TextView test;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_anglesea_building);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);


        map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

        map.addMarker(new MarkerOptions()
        .position(LOCATION_BURNABY)
        .title("Anglesea Building")
        .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));

        map.setMyLocationEnabled(true);
        CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_BURNABY,18);

        map.animateCamera(update);
        map.setMapType(GoogleMap.MAP_TYPE_SATELLITE); 



    }

    public void onClick(View v){

        map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_BURNABY,18);
        map.animateCamera(update);


    }

 public void onClick2(View v){

        map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
        CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_BURNABY,18);
        map.animateCamera(update);

        LatLng latLng = map.getCameraPosition().target;
        double lat = latLng.latitude;
        double lng = latLng.longitude;

        Toast.makeText(getBaseContext(), "lat  "+lat+"   lon  "+lng, Toast.LENGTH_SHORT).show();
        Polyline line = map.addPolyline(new PolylineOptions()
           .add(new LatLng(lat, lng),LOCATION_BURNABY )
           .width(5)
           .color(Color.RED));

    }



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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.


        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }    

        return super.onOptionsItemSelected(item);
    }
}

正如我在标题中提到的那样,我正试图从我的位置画到一条步行路线到当前的地方 这是我的代码!对不起,我是android开发的新手,我看了几个教程,但我没有设法做点什么!谢谢!如果有人知道任何可以帮助我的教程,请发帖!

0 个答案:

没有答案