Android studio da ve map de yeniyim. Hem android studio üzerinde hemde map olarak bu ilk uygulamam olacak yardım edebilirseniz sevinirim. Hemen aldığım hatayı açıklıyorum.
bu resimde gördüğünüz hatayı alıyorum, ide bu hata nedeni ile uygulamayı run etmeme engel olmuyor ancak bana burada bir hata var mesajını da yazdırıyor. Emülatörde ise uygulamayı run ettiğim zaman uygulama durdu diyor uygulama başlamıyor. Uygulama kodlarımı da burada paylaşıyorum.
@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); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationListener = new CurrentLocationListener(); criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); location = locationManager.getLastKnownLocation(provider); locationManager.requestLocationUpdates(provider, 20000, 0, locationListener);
}
/** * Manipulates the map once available. * This callback is triggered when the map is ready to be used. * This is where we can add markers or lines, add listeners or move the camera. In this case, * we just add a marker near Sydney, Australia. * If Google Play services is not installed on the device, the user will be prompted to install * it inside the SupportMapFragment. This method will only be triggered once the user has * installed Google Play services and returned to the app. */ @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; LatLng currentPosition = new LatLng(location.getLatitude(),location.getLongitude()); mMap.addMarker(new MarkerOptions().position(currentPosition).title("Şu an buradasınız")); mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(currentPosition,16)); mMap.moveCamera(CameraUpdateFactory.newLatLng(currentPosition)); }
/** * Created by Tugrul on 22.10.2015. */ public class CurrentLocationListener implements LocationListener { @Override public void onLocationChanged(Location location) { location.getLatitude(); location.getLongitude(); }
@Override public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override public void onProviderEnabled(String provider) {
}
@Override public void onProviderDisabled(String provider) {
<!-- The ACCESS_COARSE/FINE_LOCATION permissions are not required to use Google Maps Android API v2, but you must specify either coarse or fine location permissions for the 'MyLocation' functionality. --> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="com.dndyazilim.servicetextsender.permission.MAPS_RECEIVE" /> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<!-- The API key for Google Maps-based APIs is defined as a string resource. (See the file "res/values/google_maps_api.xml"). Note that the API key is linked to the encryption key used to sign the APK. You need a different API key for each encryption key, including the release key that is used to sign the APK for publishing. You can define the keys for the debug and release targets in src/debug/ and src/release/. --> <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/google_maps_key" />