2017-02-26 127 views
0

我是剛剛開始的最近2天的android的初學者。我突然對它感興趣,因爲我參加了一個關於android的短期研討會。我目前正在開發自學習和瞄準一個應用程序,上面的Jellybean 4.1支持顯示地圖。我已經知道關於API等。現在地圖顯示,但我想要的目標是當我打開地圖時只顯示某個位置。例如,我將打開該應用程序(僅適用於韓國),GPS會自動啓用,並且會確定我目前在首爾。該地圖不會顯示其他國家,但只會設置爲韓國,並且只會縮放到首爾城。這裏是我有的代碼,但現在我有點失望,因爲我收到太多的錯誤,我不明白。如何僅在Google地圖中顯示某個地方?

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { 

    private GoogleMap mMap; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_maps); 
     // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
     SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
       .findFragmentById(R.id.map); 
     mapFragment.getMapAsync(this); 

     Intent intent=new Intent("android.location.GPS_ENABLED_CHANGE"); 
     intent.putExtra("enabled", true); 
     sendBroadcast(intent); 
    } 

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

     // Add a marker in Sydney and move the camera 
     LatLng seoul = new LatLng(8.2280, 124.2452); 
     mMap.addMarker(new MarkerOptions().position(seoul).title("Marker in seoul")); 
     mMap.moveCamera(CameraUpdateFactory.newLatLng(seoul)); 
     mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(8.2280,124.2452) , 14.0f)); 
    } 
} 

我做了下面的答案,有一對夫婦更多的錯誤:

3:54:02 PM Executing tasks: [:app:assembleDebug] 
3:56:41 PM Gradle build finished with 3 error(s) in 2m 38s 461ms 
3:56:52 PM Build APK: Errors while building APK. You can find the errors in the 'Messages' view. 
3:58:54 PM Executing tasks: [:app:assembleDebug] 
3:58:57 PM Gradle build finished with 1 error(s) in 2s 642ms 
3:58:57 PM Gradle sync started 
3:58:57 PM Build APK: Errors while building APK. You can find the errors in the 'Messages' view. 
3:59:00 PM Gradle sync failed: Could not find method dexOptions() for arguments [[email protected]] on project ':app' of type org.gradle.api.Project. 
      Consult IDE log for more details (Help | Show Log) 
4:02:08 PM Executing tasks: [assemble] 
4:03:49 PM Gradle build finished with 2 error(s) in 1m 40s 546ms 
4:03:49 PM Gradle sync started 
4:03:49 PM Build APK: Errors while building APK. You can find the errors in the 'Messages' view. 
4:04:17 PM Gradle sync completed 



    Error:Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded 
Error:Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded 
Error:Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded 
Error:Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded 
Error:Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded 
Error:Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded 
Error:Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded 
Error:7 errors; aborting 
:app:transformClassesWithDexForDebug FAILED 
Error:Execution failed for task ':app:transformClassesWithDexForDebug'. 
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_101\bin\java.exe'' finished with non-zero exit value 1 
+0

哪些錯誤?你可以發佈嗎? –

回答

0

使用此:

CameraPosition cameraPosition = new CameraPosition.Builder() 

    .target(MOUNTAIN_VIEW)  // Sets the center of the map to Mountain View 

    .zoom(17)     // Sets the zoom 

    .bearing(90)    // Sets the orientation of the camera to east 

    .tilt(30)     // Sets the tilt of the camera to 30 degrees 

    .build();     // Creates a CameraPosition from the builder 

map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); 
0

這應有助於:

if (seoul!=null) { 

     mMarkerOptions = new MarkerOptions(); 
     mMarkerOptions.position(seoul); 
     mMarkerOptions.title(completeAddress); 
     mMap.addMarker(mMarkerOptions).showInfoWindow(); 
     mMap.moveCamera(CameraUpdateFactory.newLatLng(seoul)); 
     mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(seoul, 14.0f)); 
    } 
相關問題