0

I am having trouble implementing google map in a fragment.. I am passing arguments from a fragment to my "google map" fragment. i have been ok passing arguments with others.. it is just this specific problem that i am having problem.. here is my code the map fragment

import java.util.ArrayList;
import org.w3c.dom.Document;
import android.app.Dialog;
import android.graphics.Color;
import android.location.Location;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast; 
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.PolylineOptions;

public class MapActivity extends Fragment  {

GoogleMap googleMap;

Marker marker = null;
LatLng FC;
private View myFragmentView;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {
if (container == null) {
    // We have different layouts, and in one of them this
    // fragment's containing frame doesn't exist.  The fragment
    // may still be created from its saved state, but there is
    // no reason to try to create its view hierarchy because it
    // won't be displayed.  Note this is not needed -- we could
    // just run the code below, where we would create and return
    // the view hierarchy; it would just never be used.
    return null;
}
myFragmentView = inflater.inflate(R.layout.activity_map, container, false);
if (getArguments() != null)
{


LatLng fromPosition = new LatLng(getArguments().getDouble("latfrom"), getArguments().getDouble("longfrom"));
LatLng toPosition = new LatLng(getArguments().getDouble("latit"), getArguments().getDouble("longit"));

GoogleMap mMap = ((SupportMapFragment)getActivity().getSupportFragmentManager()
        .findFragmentById(R.id.map)).getMap();
GetPoly md = new GetPoly();

Document doc = md.getDocument(fromPosition, toPosition, GetPoly.MODE_DRIVING);
ArrayList<LatLng> directionPoint = md.getDirection(doc);
PolylineOptions rectLine = new PolylineOptions().width(3).color(Color.BLACK);

for(int i = 0 ; i < directionPoint.size() ; i++) {          
rectLine.add(directionPoint.get(i));
}

mMap.addPolyline(rectLine);

FC = new LatLng(getArguments().getDouble("latit"),getArguments().getDouble("longit"));
}
// Getting Google Play availability status
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity());

// Showing status
if(status!=ConnectionResult.SUCCESS){ // Google Play Services are not available

int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, getActivity(), requestCode);
dialog.show();

}else {    // Google Play Services are available

// Getting reference to the SupportMapFragment of activity_main.xml
SupportMapFragment fm = (SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map);

// Getting GoogleMap object from the fragment
googleMap = fm.getMap();



if (getArguments() != null)
{

addMarker(googleMap, getArguments().getDouble("latit"),getArguments().getDouble("longit"),getArguments().getString("station_name"), getArguments().getString("station_desc"));
addMarker(googleMap, getArguments().getDouble("latfrom"),getArguments().getDouble("longfrom"),"You are here", "You are here");
}


googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(FC, 13));

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



}
return myFragmentView;
}


private void addMarker(GoogleMap googleMap2, double lat, double lon, String title,
    String snippet) {
// TODO Auto-generated method stub
  googleMap.addMarker(new MarkerOptions().position(new LatLng(lat, lon))
          .title(title)
          .snippet(snippet));
}

}

and this is the parameters being passed..

CheckList fragobj = new CheckList();


                    Bundle bundle = new Bundle();
                    criteriavalue = list.get(position);
                    bundle.putString("station_name", criteriavalue);

                    fragobj.setArguments(bundle);
                    FragmentManager fm = getActivity().getSupportFragmentManager();
                    FragmentTransaction transaction = fm.beginTransaction();
                    transaction.replace(R.id.realtabcontent, fragobj); //Container -> R.id.contentFragment
                    transaction.commit();

the error from the logcat

01-26 02:39:38.126: D/dalvikvm(1039): GC_FOR_ALLOC freed 74K, 8% free 2660K/2880K, paused 78ms, total 97ms
01-26 02:39:38.336: D/dalvikvm(1039): GC_CONCURRENT freed 14K, 6% free 3055K/3244K, paused 3ms+21ms, total 62ms
01-26 02:39:38.496: D/GPS Enabled(1039): GPS Enabled
01-26 02:39:38.506: I/System.out(1039): Provider gps has been selected.
01-26 02:39:38.596: I/Choreographer(1039): Skipped 37 frames!  The application may be doing too much work on its main thread.
01-26 02:39:38.686: D/dalvikvm(1039): GC_CONCURRENT freed 10K, 5% free 3447K/3604K, paused 3ms+37ms, total 157ms
01-26 02:39:38.756: I/Choreographer(1039): Skipped 90 frames!  The application may be doing too much work on its main thread.
01-26 02:39:38.801: D/gralloc_goldfish(1039): Emulator without GPU emulation detected.
01-26 02:39:38.956: I/Choreographer(1039): Skipped 35 frames!  The application may be doing too much work on its main thread.
01-26 02:39:39.973: I/Choreographer(1039): Skipped 42 frames!  The application may be doing too much work on its main thread.
01-26 02:39:40.076: I/Choreographer(1039): Skipped 48 frames!  The application may be doing too much work on its main thread.
01-26 02:39:40.176: I/Choreographer(1039): Skipped 60 frames!  The application may be doing too much work on its main thread.
01-26 02:39:45.227: I/Choreographer(1039): Skipped 45 frames!  The application may be doing too much work on its main thread.
01-26 02:39:45.286: D/GPS Enabled(1039): GPS Enabled
01-26 02:39:45.296: I/System.out(1039): Provider gps has been selected.
01-26 02:39:46.656: I/Choreographer(1039): Skipped 45 frames!  The application may be doing too much work on its main thread.
01-26 02:39:46.766: I/Choreographer(1039): Skipped 46 frames!  The application may be doing too much work on its main thread.
01-26 02:39:46.866: I/Choreographer(1039): Skipped 45 frames!  The application may be doing too much work on its main thread.
01-26 02:39:46.946: I/Choreographer(1039): Skipped 46 frames!  The application may be doing too much work on its main thread.
01-26 02:39:47.336: D/GPS Enabled(1039): GPS Enabled
01-26 02:39:47.346: I/System.out(1039): Provider gps has been selected.
01-26 02:39:47.376: I/Choreographer(1039): Skipped 36 frames!  The application may be doing too much work on its main thread.
01-26 02:39:48.676: I/Choreographer(1039): Skipped 45 frames!  The application may be doing too much work on its main thread.
01-26 02:39:48.816: I/Choreographer(1039): Skipped 46 frames!  The application may be doing too much work on its main thread.
01-26 02:39:48.898: I/Choreographer(1039): Skipped 45 frames!  The application may be doing too much work on its main thread.
01-26 02:39:51.776: W/dalvikvm(1039): VFY: unable to resolve static field 1443 (MapAttrs) in Lcom/google/android/gms/R$styleable;
01-26 02:39:51.776: D/dalvikvm(1039): VFY: replacing opcode 0x62 at 0x000e
01-26 02:39:51.786: D/AndroidRuntime(1039): Shutting down VM
01-26 02:39:51.786: W/dalvikvm(1039): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
01-26 02:39:51.796: E/AndroidRuntime(1039): FATAL EXCEPTION: main
01-26 02:39:51.796: E/AndroidRuntime(1039): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
01-26 02:39:51.796: E/AndroidRuntime(1039):     at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
01-26 02:39:51.796: E/AndroidRuntime(1039):     at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
01-26 02:39:51.796: E/AndroidRuntime(1039):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
01-26 02:39:51.796: E/AndroidRuntime(1039):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
01-26 02:39:51.796: E/AndroidRuntime(1039):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
01-26 02:39:51.796: E/AndroidRuntime(1039):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
01-26 02:39:51.796: E/AndroidRuntime(1039):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-26 02:39:51.796: E/AndroidRuntime(1039):     at com.thesis.mobilehelp.MapActivity.onCreateView(MapActivity.java:50)
01-26 02:39:51.796: E/AndroidRuntime(1039):     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
01-26 02:39:51.796: E/AndroidRuntime(1039):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
01-26 02:39:51.796: E/AndroidRuntime(1039):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
01-26 02:39:51.796: E/AndroidRuntime(1039):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
01-26 02:39:51.796: E/AndroidRuntime(1039):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
01-26 02:39:51.796: E/AndroidRuntime(1039):     at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:440)
01-26 02:39:51.796: E/AndroidRuntime(1039):     at android.os.Handler.handleCallback(Handler.java:725)
01-26 02:39:51.796: E/AndroidRuntime(1039):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-26 02:39:51.796: E/AndroidRuntime(1039):     at android.os.Looper.loop(Looper.java:137)
01-26 02:39:51.796: E/AndroidRuntime(1039):     at android.app.ActivityThread.main(ActivityThread.java:5041)
01-26 02:39:51.796: E/AndroidRuntime(1039):     at java.lang.reflect.Method.invokeNative(Native Method)
01-26 02:39:51.796: E/AndroidRuntime(1039):     at java.lang.reflect.Method.invoke(Method.java:511)
01-26 02:39:51.796: E/AndroidRuntime(1039):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-26 02:39:51.796: E/AndroidRuntime(1039):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-26 02:39:51.796: E/AndroidRuntime(1039):     at dalvik.system.NativeStart.main(Native Method)

as a final note.. i read somewhere that it is not possible to implement google map with fragments or there is some other way i just don't know what it is or i have little idea. thanks in advance.

Andre malupet
  • 91
  • 3
  • 12
  • have you referenced google play services library project?? – Raghunandan Jan 26 '14 at 03:14
  • yes i have referenced it. – Andre malupet Jan 26 '14 at 03:17
  • but your stacktrace indicate you have not done it properly. http://stackoverflow.com/questions/14372391/java-lang-noclassdeffounderror-com-google-android-gms-rstyleable. quick search on SO gave meth is link. – Raghunandan Jan 26 '14 at 03:18
  • i rechecked it and yes there is no reference to google play..my bad Oh i see yes i must have forgotten it because i created a new project.. still not solved though..i'm going to upvote it after i fixed another bug or ask another question. if can't do it again – Andre malupet Jan 26 '14 at 03:31
  • after referecning re-run the app and post the updated stacktrace\ – Raghunandan Jan 26 '14 at 03:43
  • i have already solved the error it was a networkonmainthread exception.. i have no errors now but what i want to do now is something related to tabs.. i want the tabs to go back to their home even after replacing the fragment when the tab is changed.. i am using this example [link](http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/) – Andre malupet Jan 26 '14 at 04:48

0 Answers0