Reputation: 75
i am using Google maps in my sample android project but it just displays titles nothing else no maps are been display ,i have followed lynda tutorials , Map key is also generated using google map emulator and tested on real deceive as well still they does not work . Here is the code below .please help
Layout file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<com.google.android.maps.MapView
android:id="@+id/map"
android:clickable="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="MyMApKey" />
</RelativeLayout>
Map Activity :
package com.example.maptest;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
public class MainActivity extends MapActivity {
LocationListener listener ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MapView view = (MapView) findViewById(R.id.map);
view.setBuiltInZoomControls(true);
final MapController control = view.getController();
final LocationManager manager = (LocationManager) this
.getSystemService(Context.LOCATION_SERVICE);
listener = new LocationListener() {
@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
control.setCenter(new GeoPoint((int)location.getLatitude(), (int)location.getLongitude()));
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,0,listener);
}
};
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
Manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.maptest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="14" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name="com.example.maptest.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here is output
Upvotes: 1
Views: 223
Reputation: 635
try this
http://www.androidhive.info/2013/08/android-working-with-google-maps-v2/
use your api key of v2.
Upvotes: 0
Reputation: 7439
Google map api v1 is officially deprecated, you can not request for new api key to api v1. Only older api keys will work with google map api v1 which is already been created.
So please try to implement Google Map API V2.
Upvotes: 0
Reputation: 5425
There is no Api Key defined in your android manifest. Your map wont load without that. Second, you didn't define all the permissions in your android manifest. OpenGl, that's also a must. Refer to this code. This will help you..:) My Main Activity:
public class MainActivity extends FragmentActivity {
private static final int GPS_ERRORDIALOG_REQUEST = 9001;
Button btn1;
EditText et1;
EditText et2;
GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (servicesOK()) {
Toast.makeText(this, "Ready to map!!", Toast.LENGTH_LONG).show();
setContentView(R.layout.testmap);
} else {
setContentView(R.layout.activitymain);
}
/*
* et1 = (EditText)findViewById(R.id.edittext1); et2 =
* (EditText)findViewById(R.id.edittext2); btn1 =
* (Button)findViewById(R.id.button1);
*
* btn1.setOnClickListener(this);
*/
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
/*
* @Override public void onClick(View v) {
*
* Object lat = et1; Object lon = et2;
*
* Uri uri=Uri.parse("geo:"+lat.toString()+","+lon.toString()); Intent i=new
* Intent(Intent.ACTION_VIEW, uri); startActivity(i); Log.d("The Location:",
* lat.toString()+lon.toString());
*
*
* }
*/
public boolean servicesOK() {
int isAvailable = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(this);
if (isAvailable == ConnectionResult.SUCCESS) {
return true;
} else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)) {
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable,
this, GPS_ERRORDIALOG_REQUEST);
dialog.show();
} else {
Toast.makeText(this, "Cant connect!!", Toast.LENGTH_SHORT).show();
}
return false;
}
}
My Layout:
xmlns:maps="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
And finally the Android Manifest. This is the most important think you will have to consider:
package="com.mike.maps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="18" />
<permission
android:name="com.mike.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.mike.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" >
</uses-feature>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.mike.maps.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.mike.maps.SecondActivity" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="Your API KEY goes here" >
</meta-data>
</application>
Upvotes: 0
Reputation: 31
Note: Version 1 of the Google Maps Android API has been officially deprecated as of December 3rd, 2012. This means that from March 18th, 2013 you will no longer be able to request an API key for this version. No new features will be added to Google Maps Android API v1. However, apps using v1 will continue to work on devices. Existing and new developers are encouraged to use
go to this link google map api v2 step by step description is given. https://developers.google.com/maps/documentation/android/start#the_google_maps_api_key
Upvotes: 1