0

I am trying to add the google map inside one of Item of ViewPager that is HorizontalScrollView. I want to show the multiple location of store in my project so using HorizontalScrollView to scroll left to right only for googlemap and complete page inside the viewpager. Every thing is working fine without google map inside viewpager, But when i am adding google map to view pager, my app crashed.

Here is my logcat and my effort that i have done so far.

My Pastebin

I am surprised why here is authorized failure, but after commenting viewpager part, its work like charm and shows proper map and other things.

Note: ViewPager and google map is both working, but one at a time not simultaneously.

My Search in these 3 days : 1,2,3,4,5,6,7,8,9,10.

Some of Above given solutions was awesome, but i dont know why these all not working in my case.

Please help me in the same.

Thanks & Regards : Akki

Community
  • 1
  • 1
Ankita Sinha
  • 117
  • 13

3 Answers3

0

you can view reference on your api demo. placed in the directory for eclipse: <installation-directory>/sdk/extras/google/google-play-services/samples/maps you have to import the project and then you can see all the things.

Vivek Maru
  • 8,347
  • 1
  • 24
  • 34
  • As i already mentioned in my question, google map and view pager both are working individually, but how to place googlemap inside viewpager simultaneously. – Ankita Sinha Jan 15 '15 at 13:25
0

I resolved this by adding mapview inside viewpager like this :

  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);

and now every thing working fine.

Ankita Sinha
  • 117
  • 13
0
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);
}

where fragment is instance of your viewPagerFragment

in xml

<LinearLayout
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="250dp" />