Карта Google не работает внутри HorizontalScrollView с ViewPager

Я пытаюсь добавить карту Google в один из элементов ViewPager, который является HorizontalScrollView. Я хочу показать несколько местоположений магазина в моем проекте, поэтому с помощью HorizontalScrollView прокручивайте слева направо только для googlemap и заполняйте страницу внутри viewpager. Все работает нормально без карты Google внутри пейджера, но когда я добавляю карту Google для просмотра пейджера, мое приложение падает.

Вот мой логарифм и мои усилия, которые я сделал до сих пор.

Мой Pastebin

Я удивлен, почему здесь авторизованный сбой, но после комментирования части просмотра пейджера он работает как шарм и показывает правильную карту и другие вещи.

Примечание. ViewPager и карта Google работают, но не одновременно.

Мой поиск за эти 3 дня: 1,2,3, 4,5,6,7 ,8,< ссылка = "https://stackoverflow.com/questions/12117791/жест-выпуск-с-картой-в-просмотре страницы">9, 10.

Некоторые из приведенных выше решений были потрясающими, но я не знаю, почему все они не работают в моем случае.

Пожалуйста, помогите мне в том же.

С уважением и благодарностью: Акки


person Ankita Sinha    schedule 15.01.2015    source источник


Ответы (3)


вы можете просмотреть ссылку на демонстрацию вашего API. помещен в каталог для eclipse: <installation-directory>/sdk/extras/google/google-play-services/samples/maps вам нужно импортировать проект, и тогда вы сможете увидеть все.

person Vivek Maru    schedule 15.01.2015
comment
Как я уже упоминал в своем вопросе, google map и view pager работают по отдельности, но как разместить googlemap внутри viewpager одновременно. - person Ankita Sinha; 15.01.2015

Я решил это, добавив отображение карты внутри viewpager следующим образом:

  LatLng StartPoint = new LatLng(latitude, longitude);
        LatLng EndPoint = new LatLng(28.474388, 77.503990);

        mapView.onCreate(bundle);
        mapView.onResume();  
        GoogleMap map = mapView.getMap();

        map.getUiSettings().setMyLocationButtonEnabled(false);
        map.setMyLocationEnabled(true);

        MapsInitializer.initialize(getActivity());

        // Updates the location and zoom of the MapView
        Marker startPoint = map.addMarker(new MarkerOptions().position(
                StartPoint).title("startPoint"));
        Marker endPoint = map.addMarker(new MarkerOptions().position(EndPoint)
                .title("endPoint"));

        // Move the camera instantly to EndPoint with a zoom of 15.
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(EndPoint, 10));

        // Zoom in, animating the camera.
        map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);

и теперь все работает нормально.

person Ankita Sinha    schedule 16.01.2015

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

SupportMapFragment mMapFragment = SupportMapFragment.newInstance();     
FragmentManager fm = fragment.getChildFragmentManager();
fm.beginTransaction().add(R.id.map, mMapFragment).commit();
mMapFragment.getMapAsync(this);

@Override
public void onMapReady(GoogleMap googleMap) {
mGoogleMap = googleMap;

if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getContext(), 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;
}
mGoogleMap.setMyLocationEnabled(true);

buildGoogleApiClient();

mGoogleApiClient.connect();
}

protected synchronized void buildGoogleApiClient() {

mGoogleApiClient = new GoogleApiClient.Builder(getContext())
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .addApi(LocationServices.API)
        .build();
}

@Override
public void onConnected(Bundle bundle) {

if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getContext(), 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;
}
Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
        mGoogleApiClient);
if (mLastLocation != null) {
    //place marker at current position
    mGoogleMap.clear();
    //setLocation(mLastLocation.getLatitude(), mLastLocation.getLongitude());
}


mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(50000); //50 seconds
mLocationRequest.setFastestInterval(30000); //30 seconds
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
//mLocationRequest.setSmallestDisplacement(0.1F); //1/10 meter

 LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}

@Override
public void onConnectionSuspended(int i) {
Toast.makeText(customAdapter.getContext(), "onConnectionSuspended", Toast.LENGTH_SHORT).show();
}

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Toast.makeText(customAdapter.getContext(), "onConnectionFailed", Toast.LENGTH_SHORT).show();
}

@Override
public void onLocationChanged(Location location) {
sourceLat = location.getLatitude();
sourceLng = location.getLongitude();
getRestaurantDetails();
latLng = new LatLng(location.getLatitude(), location.getLongitude());
//latLng = new LatLng(lat, lng);
//Log.wtf("Lat lng", lat + " " + lng);
mGoogleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 18));
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
}

где фрагмент - это экземпляр вашего viewPagerFragment

в xml

<LinearLayout
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="250dp" />
person Laxminarayan Nayak    schedule 24.11.2016