aminos
aminos

Reputation: 1

The method setBuiltInZoomControls() is undefined for the type MapView

I try to do a marker on my google maps. I followed a tutorial but when I put setBuiltInZoomControls() an error's message appears "The method setBuiltInZoomControls() is undefined for the type MapView". what can I do to resolve the problem? mainactivity.java:

package com.googlemaps;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import com.google.android.gms.maps.MapView;
import com.google.android.maps.MapActivity;


public class MainActivity extends MapActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    MapView view= (MapView) findViewById(R.id.map);
     view.setBuiltInZoomControls(true);
}

@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();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}
}
Activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/map"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:name="com.google.android.gms.maps.MapFragment"
      />

Upvotes: 0

Views: 1161

Answers (2)

Magnus
Magnus

Reputation: 18790

I found a lot of incorrect and outdated answers to this question, might as well post what worked for me.

private GoogleMap mMap = null;


...


@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    mMap.getUiSettings().setZoomControlsEnabled(true);
}

Upvotes: 2

android_Muncher
android_Muncher

Reputation: 1057

Try the following method. Make sure you have google play services

    // Handle to Google maps
      GoogleMap googleMap;
    // Getting reference to the SupportMapFragment 
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

    // Getting GoogleMap object from the fragment
    googleMap = mapFragment.getMap();

    // Changing the map type to hybrid view
    googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
    // Changing the map type to normal view
    googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    // enable the zoom controls
    googleMap.setBuiltInZoomControls(true)

Upvotes: 0

Related Questions