Ich bin Neuling für Android-Entwicklung. Ich lerne alleine mit Internet und folgenden Tutorials. Ich mache eine App, die 3 tabs
hat, eine ist für location
zweite ist für camera
und dritte ist für pictures
. Dazu benutze ich eine tabbed activity
innerhalb android studio
. Darin verwende ich mapView
und folgte diesem tutorial und jeden Schritt darin getan. Außerdem habe ich meine apiKey
für Google Map.Google Karte lädt nicht in meine App-Gerät
Hier sind meine Codes
Manifest
<uses-permission android:name="com.example.accurat.faisal.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"
/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyBhhxKOLbX2I3kNbsZy8lbSXtjuAijKL94"
/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Location.java
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// inflat and return the layout
View rootView = inflater.inflate(R.layout.my_location, container, false);
mMapView = (MapView)rootView.findViewById(R.id.mapView);
mMapView.onCreate(savedInstanceState);
mMapView.onResume();
try
{
MapsInitializer.initialize(getActivity().getApplicationContext());
}catch (Exception e)
{
e.printStackTrace();
}
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
googleMap.setMyLocationEnabled(true);
LatLng loc = new LatLng(31.492370,74.329060);
googleMap.addMarker(new MarkerOptions().position(loc).title("I am here"));
// For zooming automatically to the location of the marker
CameraPosition cameraPosition = new CameraPosition.Builder().target(loc).zoom(12).build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
});
return rootView;
}
Ort Layout
<TextView
android:id="@+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.google.android.gms.maps.MapView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mapView" />
Außerdem bei googleMap.setMyLocationEnabled(true);
Ich bin eine rote Linie bekommen, die sagt
Ich habe versucht, die Berechtigungsprüfung zu betreten, kann aber nicht erfolgreich sein, da ich ein Neuling bin, so kann ich Schwierigkeiten stehe vor der Suche nach die richtige Lösung (en)
Update 1
Nach meinem Code aussehen wie
AktualisierungmMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if(ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
{
requestPermissions(new String[]{
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION
},1);
}
else
{
googleMap.setMyLocationEnabled(true);
LatLng loc = new LatLng(31.492370,74.329060);
googleMap.addMarker(new MarkerOptions().position(loc).title("I am Here"));
// For zooming automatically to the location of the marker
CameraPosition cameraPosition = new CameraPosition.Builder().target(loc).zoom(12).build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
}
}
});
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case 1: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
//finish();
}
return;
}
// other 'case' lines to check for other
// permissions this app might request
}
}
ich es auf meinem Android-Gerät API 16
mich entschieden und es mir build failed
mit Fehler `Fehler ist zu geben: Die Ausführung für die Task fehlgeschlagen‚: App: transformClassesWithDexForDebug‘.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536`
Jede Hilfe wäre
Unter 'this' Ich habe rote Linie – faisal1208
Verwendung' getActivity() 'anstelle von' this' weil Sie in 'fragment' sind. – W4R10CK
ja ja ich habe es, eine Sache mehr ich möchte fragen, wo man 'onRequestPermissionsResult' – faisal1208