我是android的初学者,刚刚开始过去2天。我突然对它感兴趣,因为我参加了一个关于android的简短研讨会。我目前正在开发自学习,并针对上面显示地图的Jellybean 4.1支持的应用程序。我已经知道关于API等等。现在地图显示但我想要的目的是在我打开地图时仅显示某个位置。例如,我将打开应用程序(仅限FOR SOUTH KOREA)并自动启用GPS,它将确定我目前在SEOUL。该地图不会显示其他国家,只会设置为韩国,只会缩放到首尔市。这是我的代码,但现在我有点失望,因为我收到太多错误,我不明白。
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 [build_6ssnj5v7kqqke9vdyrxx62l1w$_run_closure3@35c11173] 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));
答案 1 :(得分: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));
}