Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,806,408 Members 53,213 Now Online
XDA Developers Android and Mobile Development Forum

How make application with maps? (apiKey)

Tip us?
 
Borneq
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 3
Join Date: Feb 2014
Default How make application with maps? (apiKey)

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)
 
nikwen
Old
#2  
nikwen's Avatar
Recognized Contributor
Thanks Meter 1,327
Posts: 2,712
Join Date: 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.
 
Borneq
Old
(Last edited by Borneq; 4th April 2014 at 09:09 PM.) Reason: [/QUOTE]
#3  
Junior Member - OP
Thanks Meter 0
Posts: 3
Join Date: Feb 2014
Quote:
Originally Posted by nikwen View Post
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 (!)
 
Borneq
Old
(Last edited by Borneq; 4th April 2014 at 10:05 PM.) Reason: new attachment
#4  
Junior Member - OP
Thanks Meter 0
Posts: 3
Join Date: 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)
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes