gpt4 book ai didi

java - getMap 到 getMapAsync 隐蔽错误

转载 作者:行者123 更新时间:2023-11-30 00:39:38 25 4
gpt4 key购买 nike

我从来没有尝试过谷歌地图。这是他们使用的客户项目

compile project(':google-play-services_lib')

我必须改进他们的设计以支持最新版本的安卓

compile 'com.android.support:appcompat-v7:25.1.1'

它向我显示错误,所以我尝试这个 link .

它说可以通过将 Google Play 服务依赖项更新到 6.1.+ 来修复它。

然后我用

 compile 'com.google.android.gms:play-services:10.2.0'

支持最新版本的android。

然后它向我显示错误 getMap(),所以我将其转换为 getMapAsync() 但正在处理的是 private static GoogleMap googlemap;然后像这样分配它:

googlemap=((MapFragment)getFragmentManager().findFragmentById(R.id.places_map)).getMap();

当我把它转换成

 googlemap = ((SupportMapFragment)getActivity().getSupportFragmentManager().findFragmentById(R.id.map)).getMapAsync(this);

它告诉我错误。做什么

public class Frnt_mapActivity extends AppCompatActivity implements OnMapReadyCallback {//implements OnMapClickListener, OnMarkerDragListener  {


public static double Shop_lat;
public static double Shop_lng;
public String Shop_title;
public String Shop_address;
public String Shop_icons;


ProgressDialog mDialog;
JSONObject jsonobject3;
JSONArray jsonarray3;
// Google Map


//private static GoogleMap googlemap;

public static EditText edit_search;
public static Button btn_search;
ArrayList<SearchBeams> getAllimgs;
// Location
ArrayList<String> world_locationlist;
ArrayList<LocationBeams> worldlocation;
// Looking for
ArrayList<String> looking_forlist;
ArrayList<LookingForBeams> world_looking_for;

public static ArrayList<SearchBeams> searchdata_list;
public static ArrayList<NormalSearchBeams> normlSearchList;
public static String mid;
public static String mpost_title;
public static String mimage;
public static List<String> imglist;

ArrayList<All_products_lat_long> venueList;
Spinner mySpinner2;

public static ArrayList<SearchBeams> GetIMG;
public static TextView txtlocation;
public static TextView txtlookingfor;

public static ArrayList<All_products_lat_long> mpItm;
String vals;


private int i;
private Intent intent;
HashMap<Marker, Integer> hashMap = new HashMap<Marker, Integer>();
public static LatLng latlong;

@Override
public void onMapReady(GoogleMap map) {
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);

}


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

getActionBar().setDisplayShowHomeEnabled(true);
getActionBar().setHomeButtonEnabled(true);

mySpinner2 = (Spinner) findViewById(R.id.spin_looking_for);
// Spinner adapter
txtlookingfor = (TextView) findViewById(R.id.country);
txtlocation = (TextView) findViewById(R.id.rank);



SupportMapFragment mapFragment=getSupportFragmentManager().findFragmentById(R.id.places_map).getMapAsync(this);
googlemap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
googlemap.setMyLocationEnabled(true);
googlemap.getUiSettings().setZoomControlsEnabled(true);
googlemap.getUiSettings().setMyLocationButtonEnabled(true);
googlemap.getUiSettings().setCompassEnabled(true);
googlemap.getUiSettings().setRotateGesturesEnabled(true);
googlemap.getUiSettings().setZoomGesturesEnabled(true);
googlemap.setMyLocationEnabled(true);
intent=new Intent(Frnt_mapActivity.this,MainActivity.class);
googlemap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

@Override
public void onInfoWindowClick(Marker arg0) {
i=hashMap.get(arg0);
intent.putExtra("PRODUCT_ID", venueList.get(i).getId());
startActivity(intent);
//overridePendingTransition( R.anim.slide_right, R.anim.slide_left );
}
});


new Frnt_mIcons_Activity().execute();
new LocationList().execute();
new LookingForList().execute();

edit_search = (EditText)findViewById(R.id.txt_search);
btn_search = (Button)findViewById(R.id.btn_search);
btn_search.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
String text;
text=edit_search.getText().toString();
// text!=null &&
if(text.equals("") && text.startsWith(" ")==false){

new GetSearch_data().execute();
/*new Get_normal_search().execute();
edit_search.setText("");*/
}else

new Get_normal_search().execute();
edit_search.setText("");

//new GetSearch_data().execute();
}
});

}

他们正在调用 googlemap 并添加标记。我该如何实现它

    @Override
protected void onPostExecute(String s) {
super.onPostExecute(s);

try{
if(bd!=null){
Marker marker=googlemap.addMarker(new MarkerOptions()
.position(new LatLng(Double.parseDouble(venue.getLatitude()), Double.parseDouble(venue.getLongitude())))
.title(venue.getPost_title())
.icon(bd));
hashMap.put(marker, k);
}

}catch (Exception e){
e.printStackTrace();
}


}



switch (Integer.parseInt(venueList.get(k).getId()))
{
case 5689 :
Marker marker=googlemap.addMarker(new MarkerOptions()
.position(new LatLng(la, ln))
.title(venueList.get(k).getPost_title())
.icon(BitmapDescriptorFactory.fromResource(R.drawable.fruitandveg)));
hashMap.put(marker, k);
break;
case 5779 :
Marker marker1=googlemap.addMarker(new MarkerOptions()
.position(new LatLng(la, ln))
.title(venueList.get(k).getPost_title())
.icon(BitmapDescriptorFactory.fromResource(R.drawable.coffee)));
hashMap.put(marker1, k);
break;
.....}

最佳答案

This is a client project where they use compile project(':google-play-services_lib')

因此,您将其替换为这个(注意 -maps)

compile 'com.google.android.gms:play-services<b>-maps</b>:10.2.0'

Then it shows me error getMap() so I convert it to getMapAsync()

这是正确的,但是

你真的不应该有一个 static map 变量。如果应用程序中到处都是 static 变量,则说明设计有问题。

When i convert it to googlemap = ((SupportMapFragment)getActivity().getSupportFragmentManager().findFragmentById(R.id.map)).getMapAsync(this); It show me error

嗯,是的,那会出错

1) getActivity() 不是必需的。您已经在 Activity 类中

2) getSupportFragmentManager() 仅在您在类定义中扩展 AppCompatActivity(或 FragmentActivity)时可用

3) getMapAsync(this) 将不起作用,除非您在类定义上实现 OnMapReadyCallback

如果你做了所有这些,那么你会得到类似的东西

import com.google.android.gms.maps.OnMapReadyCallback;

public class YourActivity extends AppCompatActivity
implements OnMapReadyCallback {

private void SupportMapFragment mMapFragment;
// private GoogleMap mMap; // Commented so you don't use in onCreate

@Override
public void onMapReady(GoogleMap map) {
// this.mMap = map;
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);

// TODO: call other map setup methods
}

// Inside onCreate
mMapFragment = getSupportFragmentManager().findFragmentById(R.id.map);
mMapFragment.getMapAsync(this);

// Don't do this in onCreate
// googlemap.setMapType(GoogleMap.MAP_TYPE_NORMAL);

}

关于java - getMap 到 getMapAsync 隐蔽错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42743123/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com