android - Google Map V2 not working for me . Any sample? -
i have used many samples of google map v2, , have followed things necessary this. still having problem, map view showing , current location not being displayed on emulator.
i have created system md 5 key , api key api console , used sha 1 key in manifest. still having problem.
so please me.
my source code :
mainactivity.java
package com.googlev2.android; import android.os.bundle; import android.app.activity; import android.support.v4.app.fragmentactivity; import android.view.menu; import com.google.android.gms.maps.googlemap; import com.google.android.gms.maps.mapfragment; import com.google.android.gms.maps.supportmapfragment; import com.google.android.gms.maps.model.latlng; import com.google.android.gms.maps.model.marker; import com.google.android.gms.maps.model.markeroptions; public class mainactivity extends fragmentactivity { private googlemap mmap; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); supportmapfragment fm = (supportmapfragment)getsupportfragmentmanager(). findfragmentbyid(r.id.map); mmap = fm.getmap(); mmap.setmaptype(googlemap.map_type_satellite); final latlng ciu = new latlng(35.21843892856462, 33.41662287712097); marker ciu = mmap.addmarker(new markeroptions().position(ciu).title("my office")); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } }
and activity_main.xml
<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" /> <fragment android:name="com.google.android.gms.maps.supportmapfragment" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" /> </relativelayout>
and androidmanifest.xml :
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.googlev2.android" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="8" android:targetsdkversion="17" /> <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"/> <uses-permission android:name="android.permission.access_coarse_location" /> <uses-permission android:name="android.permission.access_fine_location"/> <permission android:name="com.googlev2.android.permission.maps_receive" android:protectionlevel="signature"> </permission> <uses-permission android:name="com.googlev2.android.permission.maps_receive"/> <uses-feature android:glesversion="0x00020000" android:required="true"/> <uses-permission android:name="android.permission.access_network_state"/> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <!-- <meta-data android:name="com.google.android.maps.v2.api_key" android:value="aizasydcil7-t3bphxgv2q-a77vnrcyjq_strgi"/> --> <activity android:name="com.googlev2.android.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> <!-- <meta-data android:name="com.google.android.maps.v2.api_key" android:value="aizasybdub-4costeeh3xqvqhwzxl2bt0aam2h8"/> --> <meta-data android:name="com.google.android.maps.v2.api_key" android:value="aizasydilovjfmlkezki5ijtl0fka-qapscd_pk"/> </application> </manifest>
if manifest file correct try man
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <fragment android:name="com.google.android.gms.maps.supportmapfragment" xmlns:map="http://schemas.android.com/apk/res-auto" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" map:cameratargetlat="33.41662287712097" map:cameratargetlng="35.21843892856462" map:camerazoom="4"/> </linearlayout>
in mainactivity.java oncreate()
public class mainactivity extends fragmentactivity { private googlemap mmap; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); supportmapfragment mapfragment = (supportmapfragment) getsupportfragmentmanager().findfragmentbyid(r.id.map); googlemap mmap = mapfragment.getmap(); mmap.addmarker(new markeroptions() .position(new latlng(35.21843892856462, 33.41662287712097)) .title("my office")); }
here result on phone
Comments
Post a Comment