How to use MapView in android using google map V2? -


i want show map in on of activity.

in google map v1 use -

 <com.google.android.maps.mapview         android:id="@+id/mapview"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:apikey="@string/api_map_key"         android:clickable="true"         android:enabled="true" /> 

and extend activity using mapactivity class.

in versing 2 uses fragment instead of mapview , have extend activity fragmentactivity instead normal activity. ex-

<fragment             android:id="@+id/map"             android:layout_width="match_parent"             android:layout_height="match_parent"             class="com.google.android.gms.maps.supportmapfragment" /> 

now can use same way create mapview instead of fragment using version 2 .()

can use mapview using v2?

yes can use mapview in v2... further details can this

https://gist.github.com/joshdholtz/4522551


somefragment.java

public class somefragment extends fragment {      mapview mapview;     googlemap map;      @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {         view v = inflater.inflate(r.layout.some_layout, container, false);          // gets mapview xml layout , creates         mapview = (mapview) v.findviewbyid(r.id.mapview);         mapview.oncreate(savedinstancestate);          // gets googlemap mapview , initialization stuff         map = mapview.getmap();         map.getuisettings().setmylocationbuttonenabled(false);         map.setmylocationenabled(true);          // needs call mapsinitializer before doing cameraupdatefactory calls         try {             mapsinitializer.initialize(this.getactivity());         } catch (googleplayservicesnotavailableexception e) {             e.printstacktrace();         }          // updates location , zoom of mapview         cameraupdate cameraupdate = cameraupdatefactory.newlatlngzoom(new latlng(43.1, -87.9), 10);         map.animatecamera(cameraupdate);          return v;     }      @override     public void onresume() {         mapview.onresume();         super.onresume();     }      @override     public void onpause() {         super.onpause();         mapview.onpause();     }      @override     public void ondestroy() {         super.ondestroy();         mapview.ondestroy();     }      @override     public void onlowmemory() {         super.onlowmemory();         mapview.onlowmemory();     }  } 

androidmanifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.example"     android:versioncode="1"     android:versionname="1.0" >      <uses-sdk         android:minsdkversion="8"         android:targetsdkversion="15" />      <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.access_coarse_location"/>     <uses-permission android:name="android.permission.access_fine_location"/>      <uses-feature         android:glesversion="0x00020000"         android:required="true"/>      <permission         android:name="com.example.permission.maps_receive"         android:protectionlevel="signature"/>     <uses-permission android:name="com.example.permission.maps_receive"/>      <application         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="your_key"/>          <activity             android:name=".homeactivity"             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> 

some_layout.xml

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="fill_parent"     android:layout_height="fill_parent" >      <com.google.android.gms.maps.mapview android:id="@+id/mapview"         android:layout_width="fill_parent"          android:layout_height="fill_parent" />  </linearlayout> 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -