Skip to main content
1 de 3
Tehz
  • 897
  • 2
  • 12
  • 29

Establecer punto de partida en un mapa

es mi primera vez que trabajo con mapas y me gustaría hacer que mi mapa se iniciara en una ciudad, por ejemplo que al abrirlo iniciara en new york, cabe destacar que ocupe un MapView y este el código que tengo en el método onCreate:

GoogleMap map;
MapView vista;


@Override
protected void onResume() {
    super.onResume();
    vista.onResume();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    vista.onDestroy();
}

@Override
protected void onPause() {
    super.onPause();
    vista.onPause();
}


@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    //Map creation
    vista = (MapView) findViewById(R.id.MapaPrincipal);
    vista.onCreate(savedInstanceState);
    map = vista.getMap();
    map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
    map.setMyLocationEnabled(true);

    //Start Point of the Map
    LatLng latLng = new LatLng(-33.4523007, -70.657779);
    CameraUpdate camera = CameraUpdateFactory.newLatLngZoom(latLng,15);
    map.animateCamera(camera);

}

@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, 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();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();
    boolean FragmentTransaction= false;
    Fragment fragment= null;

    if (id == R.id.AgregarRuta) {
        // Handle the camera action
    } else if (id == R.id.ValorarRuta) {
        fragment = new Valorar();
        FragmentTransaction= true;

    } else if (id == R.id.ReportarRuta) {

    } else if (id == R.id.Eventos) {

    } else if (id == R.id.Refresco) {

    } else if (id == R.id.Leyes) {

    }

    if(FragmentTransaction){

        getSupportFragmentManager().beginTransaction().replace(R.id.content_main, fragment).addToBackStack(null).commit();
        item.setChecked(true);
        getSupportActionBar().setTitle(item.getTitle());
    }
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

@Override
public void onFragmentInteraction(Uri uri) {

}

}

Tehz
  • 897
  • 2
  • 12
  • 29