java - Android GMaps v2 - Get location of the center of the map & map height and width -
i'm trying latitude , longitude of center of map in google maps v2 api & width , length of map.
here old code(from gmaps v1 started modify):
import com.google.android.gms.maps.googlemap; private googlemap mgooglemapview; public latlng getmapcenter() { if( mgooglemapview != null ) { return mgooglemapview.getmapcenter(); } /*if( mopenstreetmapview != null ) { return convertosmgeopoint( mopenstreetmapview.getmapcenter() ); }*/ return null; } public int getheight() { if( mgooglemapview != null ) { return mgooglemapview.getheight(); } /*if( mopenstreetmapview != null ) { return mopenstreetmapview.getheight(); }*/ return 0; } public int getwidth() { if( mgooglemapview != null ) { return mgooglemapview.getwidth(); } /*else if( mopenstreetmapview != null ) { return mopenstreetmapview.getwidth(); }*/ return 0; } how can perform same functionality mapview.getmapcenter(), mapview.getheight(), , mapview.getwidth() using android gmaps v2 api?
getting center:
googlemap map; latlng center = map.getcameraposition().target; getting width , height:
if you're adding mapfragment activity using fragmenttransaction, have provide viewgroup put fragment into. linearlayout or such. calling getwidth() , getheight() on such viewgroup should want.
hope helps. if need example, let me know.
edit - adding example:
take @ google maps android api v2, @ section named: add fragment.
under part starts you can add mapfragment activity in code, there example. in example, r.id.my_container viewgroup wrote above. somewhere in xml layout of activity, there this:
<linearlayout android:id="@+id/my_container" android:layout_width="match_parent" android:layout_height="match_parent" /> what fragmenttransaction takes mapfragment , puts child of linearlayout. child. therefore map has same width , height linearlayout.
then can need in activity this.
linearlayout mycontainer = (linearlayout) findviewbyid(r.id.my_container); int mapheight = mycontainer.getheight(); int mapwidth = mycontainer.getwidth(); i hope it's understandable.
Comments
Post a Comment