首页 / JAVA / java-为什么标记不出现?
java-为什么标记不出现?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java-为什么标记不出现?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含7448字,纯文字阅读大概需要11分钟。
内容图文
![java-为什么标记不出现?](/upload/InfoBanner/zyjiaocheng/691/827445fcac2b4ea98ef520f1bd5c2083.jpg)
我所拥有的:具有餐厅,酒吧等图像的RecyclerView,单击该图像即可将您带到地图
我想要的是:单击它们后,将带您到带有标记的地图,标记周围有您所说的地方
我的问题:我在另一个应用程序中执行了此操作,但是另一个应用程序直接向您显示了当前位置的地图,并且当您单击按钮时显示了我想要的信息.但我尝试在此应用上执行此操作,将请求添加到方法上,但标记未显示
我的问题:为什么标记不显示?如果解释随附代码示例,我将不胜感激,在此先感谢
我过去如何提出要求
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
LocationListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
checkLocationPermission();
}
//Check if Google Play Services Available or not
if (!CheckGooglePlayServices()) {
Log.d("onCreate", "Finishing test case since Google Play Services are not available");
finish();
}
else {
Log.d("onCreate","Google Play Services available.");
}
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {//esta funcion es llamada cuando el mapa esta listo para usarse(1- locacion)
mMap = googleMap;
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);//esto es lo que que dice de que forma queremos que se vea el mapa
//Initialize Google Play Services
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
buildGoogleApiClient();
mMap.setMyLocationEnabled(true);
}
}
else {
buildGoogleApiClient();
mMap.setMyLocationEnabled(true);
}
//REQUEST TRIGGERED BY BUTTON
Button btnRestaurant = (Button) findViewById(R.id.btnRestaurant);//asi se hace la peticion
btnRestaurant.setOnClickListener(new View.OnClickListener() {
String Restaurant = "restaurant";
@Override
public void onClick(View v) {
Log.d("onClick", "Button is Clicked");
mMap.clear();
String url = getUrl(latitude, longitude, Restaurant);
Object[] DataTransfer = new Object[2];
DataTransfer[0] = mMap;
DataTransfer[1] = url;
Log.d("onClick", url);
GetNearbyPlacesData getNearbyPlacesData = new GetNearbyPlacesData();
getNearbyPlacesData.execute(DataTransfer);
Toast.makeText(MapsActivity.this,"Nearby Restaurants", Toast.LENGTH_LONG).show();
}
});
我如何尝试提出要求
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
LocationListener {
private static final String EXTRA_TRIGGER_METHOD = "trigger_method";
public static Intent getIntent(Context context, boolean triggerMethod) {
Intent intent = new Intent(context, MapsActivity.class);
intent.putExtra(EXTRA_TRIGGER_METHOD, triggerMethod);
return intent;
}
private boolean triggerMethod;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
checkLocationPermission();
}
//Check if Google Play Services Available or not
if (!CheckGooglePlayServices()) {
Log.d("onCreate", "Finishing test case since Google Play Services are not available");
finish();
}
else {
Log.d("onCreate","Google Play Services available.");
}
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
triggerMethod = getIntent().getBooleanExtra(EXTRA_TRIGGER_METHOD, false);
if (triggerMethod) {
Method();
}
}
//REQUEST TRIGGERED BY METHOD
public void Method(){
String Restaurant = "restaurant";
//mMap.clear();
String url = getUrl(latitude, longitude, Restaurant);
Object[] DataTransfer = new Object[2];
DataTransfer[0] = mMap;
DataTransfer[1] = url;
Log.d("onClick", url);
GetNearbyPlacesData getNearbyPlacesData = new GetNearbyPlacesData();
getNearbyPlacesData.execute(DataTransfer);
Toast.makeText(MapsActivity.this,"Nearby Restaurants", Toast.LENGTH_LONG).show();
}
我添加标记的课程
public class GetNearbyPlacesData extends AsyncTask<Object, String, String> {
String googlePlacesData;
GoogleMap mMap;
String url;
@Override
protected String doInBackground(Object... params) {
try {
Log.d("GetNearbyPlacesData", "doInBackground entered");
mMap = (GoogleMap) params[0];
url = (String) params[1];
DownloadUrl downloadUrl = new DownloadUrl();
googlePlacesData = downloadUrl.readUrl(url);
Log.d("GooglePlacesReadTask", "doInBackground Exit");
} catch (Exception e) {
Log.d("GooglePlacesReadTask", e.toString());
}
return googlePlacesData;
}
@Override
protected void onPostExecute(String result) {
Log.d("GooglePlacesReadTask", "onPostExecute Entered");
List<HashMap<String, String>> nearbyPlacesList = null;
DataParser dataParser = new DataParser();
nearbyPlacesList = dataParser.parse(result);
ShowNearbyPlaces(nearbyPlacesList);
Log.d("GooglePlacesReadTask", "onPostExecute Exit");
}
private void ShowNearbyPlaces(List<HashMap<String, String>> nearbyPlacesList) {
for (int i = 0; i < nearbyPlacesList.size(); i++) {
Log.d("onPostExecute","Entered into showing locations");
MarkerOptions markerOptions = new MarkerOptions();
HashMap<String, String> googlePlace = nearbyPlacesList.get(i);
double lat = Double.parseDouble(googlePlace.get("lat"));
double lng = Double.parseDouble(googlePlace.get("lng"));
String placeName = googlePlace.get("place_name");
String vicinity = googlePlace.get("vicinity");
LatLng latLng = new LatLng(lat, lng);
MarkerOptions options = new MarkerOptions();
//options.position(LatLng);options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
options.title("Restaurante");
options.snippet("Burger King");
mMap.addMarker(options);
markerOptions.position(latLng);
markerOptions.title(placeName + " : " + vicinity);
mMap.addMarker(markerOptions);//esto a?ade los marcadores
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));//aqui se le pone el color a los marcadores
//move map camera
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(15));
}
}
}
解决方法:
我在您的代码中看不到任何标记,只是尝试一下,创建并添加这样的标记,然后查看它是否在地图上
MarkerOptions options = new MarkerOptions();
options.position(latitude,longitude);options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
options.title("Restaurante");
options.snippet("Burger King");
mMap.addMarker(options);
编辑
尝试更改此代码
MarkerOptions options = new MarkerOptions(); //options.position(LatLng);options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
options.title("Restaurante");
options.snippet("Burger King");
mMap.addMarker(options);
markerOptions.position(latLng);
markerOptions.title(placeName + " : " + vicinity);
mMap.addMarker(markerOptions);//esto a?ade los marcadores
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));//aqui se le pone el color a los marcadores
到这个
MarkerOptions options = new MarkerOptions();
options.position(latLng);
options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
options.title(placeName + " : " + vicinity);
mMap.addMarker(options);
内容总结
以上是互联网集市为您收集整理的java-为什么标记不出现?全部内容,希望文章能够帮你解决java-为什么标记不出现?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。