我的标记不起作用。我不知道为什么。 标记没有onMapReady方法中的任何工作。在onCreate.Works运行其他。它的印刷品是“hata1”和“hata2”。 当我创建新项目时,不会从/sdk/extras/../google_play/services导入。我得到“找不到文件/settings.jar”错误。所以我也不想要新项目。
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
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.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import java.util.*;
import android.os.Bundle;
import com.google.android.*;
import android.graphics.*;
import android.view.View;
import android.widget.Toast;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback{
private GoogleMap myMap;
public static final LatLng PERTH = new LatLng(36.57, 36.17);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
Toast.makeText(getApplicationContext(),"hata1",Toast.LENGTH_SHORT).show();
if(myMap!=null) {
Marker marker = myMap.addMarker(new MarkerOptions()
.position(PERTH)
.title("Marker").visible(true));
marker.showInfoWindow();
myMap.moveCamera(CameraUpdateFactory.newLatLngZoom(PERTH, 13));
}
else
{
Toast.makeText(getApplicationContext(),"hata2",Toast.LENGTH_SHORT).show();
}
}
@Override
public void onMapReady(GoogleMap myMap) {
}
}
答案 0 :(得分:0)
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback{
private GoogleMap myMap;
public static final LatLng PERTH = new LatLng(36.57, 36.17);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
getHandleOnMap();
}
private void getHandleOnMap()
{
SupportMapFragment mapFragment = (SupportMapFragment) this.getChildFragmentManager()
.findFragmentById(R.id.mapFragment);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap myMap) {
googleMap.addMarker(new MarkerOptions()
.position(PERTH)
.title("Hello"));
}
}
如果您遇到任何崩溃或错误,请分享详细日志
答案 1 :(得分:0)
你能这样试试吗?因为onMapReady()
在GoogleMap
准备就绪后会自动生成GoogleMap
,并且您需要public class MapsActivity extends FragmentActivity implements OnMapReadyCallback{
private GoogleMap myMap;
public static final LatLng PERTH = new LatLng(36.57, 36.17);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
MapFragment mapFragment = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap myMap) {
Toast.makeText(getApplicationContext(),"hata1",Toast.LENGTH_SHORT).show();
if(myMap!=null) {
Marker marker = myMap.addMarker(new MarkerOptions()
.position(PERTH)
.title("Marker").visible(true));
marker.showInfoWindow();
myMap.moveCamera(CameraUpdateFactory.newLatLngZoom(PERTH, 13));
}
else
{
Toast.makeText(getApplicationContext(),"hata2",Toast.LENGTH_SHORT).show();
}
}
}
个对象才能使用。
Map<String, String> map = new HashMap<>();
map.put("name", Name);.....so on