我尝试在谷歌地图上做一个标记。 我按照教程进行了操作,但是当我输入setBuiltInZoomControls()时,会出现错误消息"方法setBuiltInZoomControls()未定义为MapView"类型。 我该怎么做才能解决问题? 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"
/>
答案 0 :(得分:1)
我发现这个问题有很多不正确和过时的答案,不妨发布对我有用的内容。
private GoogleMap mMap = null;
...
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.getUiSettings().setZoomControlsEnabled(true);
}
答案 1 :(得分:0)
尝试以下方法。确保您有谷歌播放服务
// 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)