Android Google Map V2, Output is not showing -
i tried lot map tutorials mt emulator showing blank window. tried google map view sample code showing same. below code tried, please provide solution this
activity
package info.androidhive.googlemapsv2; import android.app.activity; import android.os.bundle; import android.util.log; import android.widget.toast; import com.google.android.gms.maps.cameraupdatefactory; import com.google.android.gms.maps.googlemap; import com.google.android.gms.maps.mapfragment; import com.google.android.gms.maps.model.bitmapdescriptorfactory; import com.google.android.gms.maps.model.cameraposition; import com.google.android.gms.maps.model.latlng; import com.google.android.gms.maps.model.markeroptions; public class mainactivity extends activity { // google map private googlemap googlemap; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); try { // loading map initilizemap(); // changing map type googlemap.setmaptype(googlemap.map_type_normal); // googlemap.setmaptype(googlemap.map_type_hybrid); // googlemap.setmaptype(googlemap.map_type_satellite); // googlemap.setmaptype(googlemap.map_type_terrain); // googlemap.setmaptype(googlemap.map_type_none); // showing / hiding current location googlemap.setmylocationenabled(true); // enable / disable zooming controls googlemap.getuisettings().setzoomcontrolsenabled(false); // enable / disable location button googlemap.getuisettings().setmylocationbuttonenabled(true); // enable / disable compass icon googlemap.getuisettings().setcompassenabled(true); // enable / disable rotate gesture googlemap.getuisettings().setrotategesturesenabled(true); // enable / disable zooming functionality googlemap.getuisettings().setzoomgesturesenabled(true); double latitude = 17.385044; double longitude = 78.486671; // lets place 10 random markers (int = 0; < 10; i++) { // random latitude , logitude double[] randomlocation = createrandlocation(latitude, longitude); // adding marker markeroptions marker = new markeroptions().position( new latlng(randomlocation[0], randomlocation[1])) .title("hello maps " + i); log.e("random", "> " + randomlocation[0] + ", " + randomlocation[1]); // changing marker color if (i == 0) marker.icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_azure)); if (i == 1) marker.icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_blue)); if (i == 2) marker.icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_cyan)); if (i == 3) marker.icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_green)); if (i == 4) marker.icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_magenta)); if (i == 5) marker.icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_orange)); if (i == 6) marker.icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_red)); if (i == 7) marker.icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_rose)); if (i == 8) marker.icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_violet)); if (i == 9) marker.icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_yellow)); googlemap.addmarker(marker); // move camera last position zoom level if (i == 9) { cameraposition cameraposition = new cameraposition.builder() .target(new latlng(randomlocation[0], randomlocation[1])).zoom(15).build(); googlemap.animatecamera(cameraupdatefactory .newcameraposition(cameraposition)); } } } catch (exception e) { e.printstacktrace(); } } @override protected void onresume() { super.onresume(); initilizemap(); } /** * function load map if map not created create * */ private void initilizemap() { if (googlemap == null) { googlemap = ((mapfragment) getfragmentmanager().findfragmentbyid( r.id.map)).getmap(); // check if map created or not if (googlemap == null) { toast.maketext(getapplicationcontext(), "sorry! unable create maps", toast.length_short) .show(); } } } /* * creating random postion around location testing purpose */ private double[] createrandlocation(double latitude, double longitude) { return new double[] { latitude + ((math.random() - 0.5) / 500), longitude + ((math.random() - 0.5) / 500), 150 + ((math.random() - 0.5) * 10) }; } }
layout
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <fragment android:id="@+id/map" android:name="com.google.android.gms.maps.mapfragment" android:layout_width="match_parent" android:layout_height="match_parent"/> </relativelayout>
manifest file
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="info.androidhive.googlemapsv2" android:versioncode="1" android:versionname="1.0" > <permission android:name="info.androidhive.googlemapsv2.permission.maps_receive" android:protectionlevel="signature" /> <uses-permission android:name="info.androidhive.googlemapsv2.permission.maps_receive" /> <uses-sdk android:minsdkversion="12" android:targetsdkversion="17" /> <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-permission android:name="android.permission.write_external_storage" /> <!-- required show current location --> <uses-permission android:name="android.permission.access_coarse_location" /> <uses-permission android:name="android.permission.access_fine_location" /> <!-- required opengl es 2.0. maps v2 --> <uses-feature android:glesversion="0x00020000" android:required="true" /> <!-- requires opengl es version 2 --> <uses-feature android:glesversion="0x00020000" android:required="true" /> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name"> <activity android:name="info.androidhive.googlemapsv2.mainactivity" android:label="@string/app_name" android:theme="@style/appbasetheme"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <!-- goolge api key --> <meta-data android:name="com.google.android.maps.v2.api_key" android:value="aizasybzmlkov4sj-m5jo9p6wksdax4tejdvlgo" /> </application> </manifest>
output
![enter image description here][1]
console
[2013-09-04 12:21:48 - googlemapsv2] ------------------------------ [2013-09-04 12:21:48 - googlemapsv2] android launch! [2013-09-04 12:21:48 - googlemapsv2] adb running normally. [2013-09-04 12:21:48 - googlemapsv2] performing info.androidhive.googlemapsv2.mainactivity activity launch [2013-09-04 12:21:48 - googlemapsv2] automatic target mode: launching new emulator compatible avd '1' [2013-09-04 12:21:48 - googlemapsv2] launching new emulator virtual device '1' [2013-09-04 12:21:49 - googlemapsv2] new emulator found: emulator-5554 [2013-09-04 12:21:49 - googlemapsv2] waiting home ('android.process.acore') launched... [2013-09-04 12:22:33 - googlemapsv2] home on device 'emulator-5554' [2013-09-04 12:22:33 - googlemapsv2] uploading googlemapsv2.apk onto device 'emulator-5554' [2013-09-04 12:22:35 - googlemapsv2] installing googlemapsv2.apk... [2013-09-04 12:23:32 - googlemapsv2] success! [2013-09-04 12:23:32 - googlemapsv2] starting activity info.androidhive.googlemapsv2.mainactivity on device emulator-5554 [2013-09-04 12:23:33 - googlemapsv2] activitymanager: starting: intent { act=android.intent.action.main cat=[android.intent.category.launcher] cmp=info.androidhive.googlemapsv2/.mainactivity } [2013-09-04 12:23:34 - googlemapsv2] ------------------------------ [2013-09-04 12:23:34 - googlemapsv2] android launch! [2013-09-04 12:23:34 - googlemapsv2] adb running normally. [2013-09-04 12:23:34 - googlemapsv2] performing info.androidhive.googlemapsv2.mainactivity activity launch [2013-09-04 12:23:34 - googlemapsv2] automatic target mode: using existing emulator 'emulator-5554' running compatible avd '1' [2013-09-04 12:23:34 - googlemapsv2] ------------------------------ [2013-09-04 12:23:34 - googlemapsv2] android launch! [2013-09-04 12:23:34 - googlemapsv2] adb running normally. [2013-09-04 12:23:34 - googlemapsv2] performing info.androidhive.googlemapsv2.mainactivity activity launch [2013-09-04 12:23:34 - googlemapsv2] automatic target mode: using existing emulator 'emulator-5554' running compatible avd '1' [2013-09-04 12:23:36 - googlemapsv2] application deployed. no need reinstall. [2013-09-04 12:23:36 - googlemapsv2] starting activity info.androidhive.googlemapsv2.mainactivity on device emulator-5554 [2013-09-04 12:23:40 - googlemapsv2] application deployed. no need reinstall. [2013-09-04 12:23:40 - googlemapsv2] starting activity info.androidhive.googlemapsv2.mainactivity on device emulator-5554 [2013-09-04 12:23:40 - googlemapsv2] activitymanager: starting: intent { act=android.intent.action.main cat=[android.intent.category.launcher] cmp=info.androidhive.googlemapsv2/.mainactivity } [2013-09-04 12:23:40 - googlemapsv2] activitymanager: warning: activity not started, current task has been brought front [2013-09-04 12:23:42 - googlemapsv2] activitymanager: starting: intent { act=android.intent.action.main cat=[android.intent.category.launcher] cmp=info.androidhive.googlemapsv2/.mainactivity } [2013-09-04 12:23:42 - googlemapsv2] activitymanager: warning: activity not started, current task has been brought front [1]: http://i.stack.imgur.com/mjkpm.png
it seems have not created own api key. first have generate api key using sha1 certificate keystore try.
if want generate sha1 certificate using keystore follow :
how can md5 fingerprint java's keytool, not sha-1?
to enable service , generating key visit : https://code.google.com/apis/console/
and make sure enable "google maps android api v2" in service tab of google api console.
Comments
Post a Comment