Andrei Pascale
Andrei Pascale

Reputation: 232

Google Maps looks like an image

I have two Google Maps in my application, which I have implemented in the same way. One is working and one is not. The latter looks like an image and I can't interact with it. I can add markers and move the camera, but the info window doesn't show when I click the marker I can't move it, zoom in and zoom out. It looks like an image, a preview.

Here is the code:

public class MapFragment extends Fragment implements OnMapReadyCallback{

    private GoogleMap mMap;
    private static Double latitude;
    private static Double longitude;
    private static String title;

    public static MapFragment newInstance(Double mLatitude, Double mLongitude, String mTitle) {
        latitude=mLatitude;
        longitude=mLongitude;
        title=mTitle;
        MapFragment fragment = new MapFragment();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_map, container, false);
        SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager()
                .findFragmentById(R.id.map_details);
        mapFragment.getMapAsync(this);
        return view;
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
        mMap.getUiSettings().setAllGesturesEnabled(true);
        mMap.getUiSettings().setMapToolbarEnabled(false);
        mMap.addMarker(new MarkerOptions()
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.location_icon))
                .position(new LatLng(latitude, longitude))
                .title(title));
        CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(latitude,longitude)).zoom(12f).build();
        CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition);
        mMap.moveCamera(cameraUpdate);
    }

    public interface OnMapFragmentInteractionListener {
        void onMapFragmentInteraction(Uri uri);
    }

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

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

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

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

Upvotes: 1

Views: 72

Answers (2)

Eugene Troyanskii
Eugene Troyanskii

Reputation: 892

I'm just guessing but in code that you posted i see one mistake. To be sure you have to check your imports in the place when you try to use your MapFragment. As I said I guess that in one place it's imported from google pacage and another one from your class. The problem is that the MapFragment that you post here isn't a google MapFragment because you extants it from simple Fragment. To be sure rename your own MapFragment to CustomMapFragment and try to extands from MapFragment or just use it without customize.

Upvotes: 0

Simon Harvan
Simon Harvan

Reputation: 701

You should take a look at XML. There is liteMode and when it's set to true it does exactly what you are describing.

<com.google.android.gms.maps.MapView
            android:id="@+id/row_map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            map:liteMode="true"
            map:mapType="none" />

Here look at documentation

Upvotes: 1

Related Questions