我在片段中实现谷歌地图时遇到了麻烦..我正在将片段中的参数传递给我的“谷歌地图”片段。我一直在和其他人一起传递论据。 只是这个具体的问题,我有问题.. 这是我的代码地图片段
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));
}
}
这是传递的参数..
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();
来自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)
作为最后的注释..我在某处读到不可能用片段实现谷歌地图,或者有一些其他方式我只是不知道它是什么或我不知道。提前谢谢。