Post Reply

How make application with maps? (apiKey)

OP Borneq

15th February 2014, 08:08 PM   |  #1  
OP Junior Member
Thanks Meter: 0
 
3 posts
Join Date:Joined: Feb 2014
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:

8A5:....: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 :
Quote:

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!
Attached Files
File Type: zip borneqProgram.zip - [Click for QR Code] (61.1 KB, 5 views)
File Type: zip logCat.zip - [Click for QR Code] (1.0 KB, 5 views)
16th February 2014, 10:09 PM   |  #2  
nikwen's Avatar
Recognized Contributor
Thanks Meter: 1,378
 
2,765 posts
Join Date:Joined: Feb 2013
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.NullPointerException
at com.borneq.heregpslocation.MainActivity.setButtonState(MainActivity.java:77)
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.
4th April 2014, 08:49 PM   |  #3  
OP Junior Member
Thanks Meter: 0
 
3 posts
Join Date:Joined: Feb 2014
Quote:
Originally Posted by nikwen

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 by Borneq; 4th April 2014 at 09:09 PM. Reason: [/QUOTE]
4th April 2014, 09:15 PM   |  #4  
OP Junior Member
Thanks Meter: 0
 
3 posts
Join Date:Joined: Feb 2014
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
Attached Files
File Type: zip HereGPSLocation.zip - [Click for QR Code] (63.3 KB, 0 views)
Last edited by Borneq; 4th April 2014 at 10:05 PM. Reason: new attachment
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Java for Android App Development by ThreadRank