Android 标记不起作用
Android Marker does not work
我的记号笔不起作用。我不知道为什么。
标记在 onMapReady method.Works 中没有任何作用 onCreate.But 它正在运行 else 。它的打印 "hata1" 和 "hata2"。
当我创建新项目时,不会从 /sdk/extras/../google_play/services 导入。我得到 "cannot find file /settings.jar" error.So 我也不想要新项目。
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) {
}
}
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"));
}
}
如果您遇到任何崩溃或错误,请分享详细的日志
你可以这样试试吗?因为 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();
}
}
}
我的记号笔不起作用。我不知道为什么。 标记在 onMapReady method.Works 中没有任何作用 onCreate.But 它正在运行 else 。它的打印 "hata1" 和 "hata2"。 当我创建新项目时,不会从 /sdk/extras/../google_play/services 导入。我得到 "cannot find file /settings.jar" error.So 我也不想要新项目。
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) {
}
}
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"));
}
}
如果您遇到任何崩溃或错误,请分享详细的日志
你可以这样试试吗?因为 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();
}
}
}