Problem with api V2 maps Android

1

the query would be that I would not know how to use it well, since I'm guiding myself by what the tutorials say and in SO (in English) but I have not managed to make it work I have the following information:

content_locales.xml

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/imgLogoLocal"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:contentDescription="@string/logo_local" />

    <fragment
        android:id="@+id/mapview"
        android:layout_width="match_parent"
        android:layout_height="220dp"
        class="com.reservamos.MapFragment"/>

    <Button
        android:id="@+id/btnReservar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/solicitar_reserva" />
</LinearLayout>

LocalActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    final Context context = getContext();
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_locales);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    imagenlocal = (ImageView)findViewById(R.id.imgLogoLocal);
    android.support.v4.app.Fragment fragment = new android.support.v4.app.Fragment();
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.mapview, fragment);
    transaction.commit();

    int id;
    id = getIntent().getIntExtra("id",0);
    Servicio ser = new Servicio();
    Locales local = new Locales();
    try {
        local = ser.GetLocal(context, id);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    toolbar.setTitle(local.getNombre());
    if (imagenlocal != null){
        byte[] decodeString  = new byte[0];
        try {
            decodeString = Base64.decode(local.getImagen(), Base64.NO_OPTIONS);
        } catch (IOException e) {
            e.printStackTrace();
        }

        Bitmap decodebitmap = BitmapFactory.decodeByteArray(decodeString,
                0, decodeString.length);
        imagenlocal.setImageBitmap(decodebitmap);
    }
}

and the map

MapFragment.java and fragment_map.xml

taken from link

I do not place the classes because I do not modify any of the classes belonging to the tutorial

The problem is that when I enter to show me the map, I logged the following

  

05-11 01: 00: 55.262 10220-10242 / com.reservamos I / art: Background partial concurrent mark sweep GC freed 682293 (16MB) AllocSpace objects, 100 (1600KB) objects, 23% free, 51MB / 67MB , paused 61,646ms total 448.110ms

     

05-11 01: 00: 56.074 10220-10242 / com.reservamos I / art: Background sticky concurrent mark sweep GC freed 671925 (16MB) AllocSpace objects, 94 (1504KB) objects, 20% free, 53MB / 67MB , paused 89.349ms total 359.503ms

     

05-11 01: 00: 56.921 10220-10242 / com.reservamos I / art: Background partial concurrent mark sweep GC freed 707530 (16MB) AllocSpace objects, 94 (1504KB) Objects, 22% free, 56MB / 72MB , paused 66.386ms total 467.650ms

and continue with a similar log, until I kill the application directly.

Is there something I will be doing wrong?

Before you ask me, yes, I have the api key enabled to try and the permissions are as follows:

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.INTERNET" />


<permission
    android:name="com.example.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>
<uses-permission android:name="com.example.permission.MAPS_RECEIVE"/>

any contribution they make is appreciated

Start of the log, where apparently the error could be

  

05-12 00: 21: 23.256 25931-25936 / com.reservamos I / art: Compiler   allocated 4MB to compile void   android.widget.TextView. (android.content.Context,   android.util.AttributeSet, int, int) 05-12 00: 21: 43.932   25931-25936 / com.reservamos I / art: Do full code cache collection,   code = 126KB, data = 109KB 05-12 00: 21: 43.933 25931-25936 / com.reservamos   I / art: After code cache collection, code = 120KB, data = 87KB 05-12   00: 21: 44.075 25931-25936 / com.reservamos I / art: Do partial code cache   collection, code = 121KB, data = 97KB 05-12 00: 21: 44.078   25931-25936 / com.reservamos I / art: After code cache collection,   code = 118KB, data = 95KB       Increasing code cache capacity to 512KB

fragment in which the error could be, since it is referencing something that is not an error, but as an informative message

  

05-12 00: 21: 20.047 25931-25931 / com.reservamos W / System: ClassLoader   referenced unknown path: /data/app/com.reservamos-2/lib/arm 05-12   00: 21: 20.187 25931-25931 / com.reservamos W / art: Before Android 4.1,   method android.graphics.PorterDuffColorFilter   android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter (android.graphics.PorterDuffColorFilter,   android.content.res.ColorStateList, android.graphics.PorterDuff $ Mode)   would have incorrectly overridden the package-private method in   android.graphics.drawable.Drawable

Then, follow the first item that you put on the Garbage Collector

    
asked by Pablo Ezequiel Ferreyra 11.05.2018 в 06:09
source

1 answer

0

the only thing that made me worth it to be able to make it functional, was to generate this fragment

public class MapViewFragment extends Fragment {

    MapView mMapView;
    private GoogleMap googleMap;
    private LatLng coord;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.location_fragment, container, false);

        mMapView = (MapView) rootView.findViewById(R.id.mapView);
        mMapView.onCreate(savedInstanceState);

        mMapView.onResume(); // needed to get the map to display immediately

        try {
            MapsInitializer.initialize(getActivity().getApplicationContext());
        } catch (Exception e) {
            e.printStackTrace();
        }

        mMapView.getMapAsync(new OnMapReadyCallback() {
            @SuppressLint("MissingPermission")
            @Override
            public void onMapReady(GoogleMap mMap) {
                googleMap = mMap;

                // For showing a move to my location button
                googleMap.setMyLocationEnabled(true);

                // For dropping a marker at a point on the Map

                googleMap.addMarker(new MarkerOptions().position(coord).title("Marker Title").snippet("Marker Description"));

                // For zooming automatically to the location of the marker
                CameraPosition cameraPosition = new CameraPosition.Builder().target(coord).zoom(15).build();
                googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
            }
        });

        return rootView;
    }

    @Override
    public void onResume() {
        super.onResume();
        mMapView.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        mMapView.onPause();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mMapView.onDestroy();
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        mMapView.onLowMemory();
    }

}

and its respective layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <com.google.android.gms.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>
    
answered by 16.05.2018 / 06:51
source