How make application with maps? (apiKey)

Search This thread

Borneq

Member
Feb 15, 2014
5
0
Hi, I am new in xda-developers forum. I have written my first simple application which uses GPS. Now I want to use Google Maps. Is problem because it want apiKey. My apiKey is in Google Code Api's Console. There is Android apps:

8A:D5:....:72:88:AE;com.borneq.heregpslocation and ApiKey : AIzaSyCh0XWRIXaTizxYcnWO8K7eFLZEysfGJvM (it is public or private?)
I modified three file to do with maps:
* AndroidManifest.xml:
Code:
<permission
        android:name="com.borneq.heregpslocation.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
    
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    <uses-permission android:name="com.borneq.heregpslocation.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Code:
<uses-library android:name="com.google.android.maps" />
Code:
<meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyCh0XWRIXaTizxYcnWO8K7eFLZEysfGJvM" />

Second file is activity_main.xml :
Code:
    <com.google.android.maps.MapView
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:apiKey="AIzaSyCh0XWRIXaTizxYcnWO8K7eFLZEysfGJvM"
        android:clickable="true" />
Third is .MainActivity.java :
import com.google.android.maps.MapActivity;
public class MainActivity extends MapActivity implements OnClickListener {
Previously used controls I commnted

Project compiles but application breaks at start. I attach source: zipped program and logCat
Thanks!
 

Attachments

  • borneqProgram.zip
    61.1 KB · Views: 5
  • logCat.zip
    1 KB · Views: 5

nikwen

Senior Member
Feb 1, 2013
3,142
1,597
Berlin, Germany
www.nikwen.de
The app crashs in line 77 of MainActivity. It's a NullPointerException.

Code:
boolean isGps = locationManager.isProviderEnabled("gps");

The reason for the crash is that in onCreate you commented this line out:
Code:
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

Due to this the variable locationManager is null and it crashes later because it cannot handle a null value. Just uncomment the line from onCreate which I pasted above. That's it. ;)

How did I know that? It's in the logcat:
Code:
Caused by: java.lang.[B]NullPointerException[/B]
at com.borneq.heregpslocation.MainActivity.setButtonState([B]MainActivity.java:77[/B])
This guide might help you understand logcats (focus on that part of the guide): [GUIDE] Debugging apps You'll definitely need that knowledge if you want to do serious Android development. The earlier you learn it the better. Good luck. ;)
 

Borneq

Member
Feb 15, 2014
5
0
The app crashs in line 77 of MainActivity. It's a NullPointerException.

Code:
boolean isGps = locationManager.isProviderEnabled("gps");

The reason for the crash is that in onCreate you commented this line out:
Code:
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

Thanks, I remove by comment old controls and not noticed that comment also locationManager (!)
 
Last edited:

Borneq

Member
Feb 15, 2014
5
0
I correct; removed reference to commented controls and I don't have error but I can't see maps
Is "class MainActivity extends MapActivity" but np map, only lattice
 

Attachments

  • HereGPSLocation.zip
    63.3 KB · Views: 1
Last edited: