简体   繁体   English

我如何提出这个要求

[英]How can I make this request

What I had: An application that when you opened, it showed you a map with 3 buttons that said, "Restaurant", "Hospitals","Bars", and once clicked one of them they showed you this places nearby 我所拥有的:一个应用程序,当您打开时,它向您显示带有3个按钮的地图,上面分别显示“餐厅”,“医院”,“酒吧”,然后单击其中的一个,便向您显示了附近的这个地方

What I have: For aesthetic questions an app that when you open, it shows you a RecyclerView with images, and when you click one of these images takes you to a map with your current position. 我所拥有的:对于美学方面的问题,一个应用程序在您打开时会显示一个带有图像的RecyclerView,并且当您单击其中的一张图像时,会将您带到当前位置的地图。

What I want: That when I click on one of the images of the RecyclerView for example Restaurants, it show a map with the restaurants near me, but making this request from the OnClickListener that I have in my RecyclerView's Adapter on the OnBindViewHolder() method 我想要的是:当我单击RecyclerView的图像之一(例如“餐馆”)时,它会显示一张地图,其中包含我附近的餐馆,但是通过OnBindViewHolder()方法在RecyclerView的Adapter中从OnClickListener发出此请求

My Question: How do I make this request if the elements such as Latitude and Longitude are in another Activity and also within a Method called OnMapReady () in which I used to make the request with the buttons I had initially. 我的问题:如果诸如纬度和经度之类的元素在另一个Activity中以及在称为OnMapReady()的方法中,该方法我曾经使用最初使用的按钮发出请求,那么该如何发出请求。 Please I would appreciate the answers with code examples, I am still not very good at programming and there are millions of terms that I do not understand, thanks in advance 请欣赏代码示例的答案,我仍然不太擅长编程,还有数百万我不理解的术语,在此先感谢

My RecyclerView and where I want to make the request 我的RecyclerView以及我要在哪里提出要求

 @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
        holder.etiNombre.setText(listalugares.get(position).getNombre());
        holder.foto.setImageResource(listalugares.get(position).getFoto());

        holder.foto.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (position == 0){
                    Intent myIntent = new Intent(context, MapsActivity.class);
                    context.startActivity(myIntent);

                }
            }
        });
    }

Where I used to make my request 我以前提出要求的地方

@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);
        }
        Button btnRestaurant = (Button) findViewById(R.id.btnRestaurant);
        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();
            }
        });

To pass data from an activity to another, you'll have to use Intent 's extras field. 要将数据从一个活动传递到另一个活动,您必须使用Intentextras字段。 It's a Bundle (a key/value data-structure) where you can store everything you want (with size constraints, so it's usually a good idea to pass only IDs or stuff like that, not the actual data). 这是一个Bundle (键/值数据结构),您可以在其中存储所需的所有内容(有大小限制,因此通常只传递ID或类似的东西,而不传递实际数据是个好主意)。

What you can do here is: in your adapter's onClick method, add an extra field to the Intent , containing the information type you want to display (either restaurant, bar or hospital). 您可以在这里执行的操作是:在适配器的onClick方法中,向Intent添加一个额外的字段,其中包含要显示的信息类型(餐厅,酒吧或医院)。 Then, in your second activity (the one containing the map), in the onCreate method, read the field from the Intent . 然后,在第二个活动(包含地图的活动)中,在onCreate方法中,从Intent读取字段。 Then you can still place your Nearby Places request in the onMapReady method, using the field to determine which type you're requesting, instead of depending on a specific button click event. 然后,您仍然可以使用字段确定您要请求的类型,而不是依赖特定的按钮单击事件,将onMapReady附近的请求放置在onMapReady方法中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM