Get latitude and longitude on the android side of the gold map

Source: Internet
Author: User

<?XML version= "1.0" encoding= "Utf-8"?><Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:id= "@+id/activity_select_point"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= "Com.example.euphemiaxiao.feedback.selectPoint">    <com. Amap.api.maps.MapView Android:id= "@+id/map"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:layout_above= "@+id/doneselect">    </Com.amap.api.maps.MapView>    <ButtonAndroid:text= "Confirm selected Point"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:id= "@+id/doneselect"Android:background= "@android: Color/holo_blue_light"android:textsize= "18SP"Android:layout_centerhorizontal= "true"Android:layout_alignparentbottom= "true"/></Relativelayout>

 PackageCom.example.euphemiaxiao.feedback;Importandroid.content.Intent;ImportAndroid.os.Bundle;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.view.View;ImportAndroid.widget.Button;ImportCom.amap.api.maps.AMap;Importcom.amap.api.maps.CameraUpdateFactory;ImportCom.amap.api.maps.MapView;Importcom.amap.api.maps.model.BitmapDescriptorFactory;ImportCom.amap.api.maps.model.LatLng;Importcom.amap.api.maps.model.MarkerOptions; Public classSelectpointextendsAppcompatactivityImplementsamap.onmapclicklistener{PrivateButton Doneselect; PrivateMapview Mmapview =NULL; PrivateAMap AMap =NULL; Doublelatitude; Doublelongtitude; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_select_point); //Get map Control ReferenceMmapview =(Mapview) Findviewbyid (R.ID.MAP); //Execute Mmapview.oncreate (savedinstancestate) When activity executes onCreate, create mapmmapview.oncreate (savedinstancestate);        Init (); Doneselect=(Button) Findviewbyid (r.id.doneselect); Doneselect.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {Intent Intent=NewIntent (Selectpoint. This, Feedback.class); Intent.putextra ("Latitude", latitude); Intent.putextra ("Longtitude", longtitude);            StartActivity (Intent);    }        }); }    Private voidinit () {if(AMap = =NULL) {AMap=Mmapview.getmap ();        Setupmap (); }    }    Private voidSetupmap () {Amap.showindoormap (true); LATLNG latlng=NewLATLNG (39.92448, 116.518295); Amap.movecamera (CAMERAUPDATEFACTORY.CHANGELATLNG (LATLNG));//Set Center pointAmap.movecamera (Cameraupdatefactory.zoomto (18));//set the map to zoom in and out smallAmap.setonmapclicklistener ( This); } @Overrideprotected voidOnDestroy () {Super. OnDestroy (); //Execute Mmapview.ondestroy () when activity executes OnDestroy, destroy mapMmapview.ondestroy (); } @Overrideprotected voidOnresume () {Super. Onresume (); //perform mmapview.onresume () when activity executes Onresume, redraw load mapMmapview.onresume (); } @Overrideprotected voidOnPause () {Super. OnPause (); //Execute Mmapview.onpause () when activity executes onPause, pausing map drawingMmapview.onpause (); } @Overrideprotected voidonsaveinstancestate (Bundle outstate) {Super. Onsaveinstancestate (outstate); //mmapview.onsaveinstancestate (outstate) is executed when activity executes onsaveinstancestate, saving the current state of the mapmmapview.onsaveinstancestate (outstate); } @Override Public voidOnmapclick (latlng latlng) {amap.clear (); Latitude=Latlng.latitude; Longtitude=Latlng.longitude; Markeroptions markeroptions=Newmarkeroptions ();        Markeroptions.icon (Bitmapdescriptorfactory.fromresource (R.drawable.placeholder));        Markeroptions.position (LATLNG);        Amap.addmarker (markeroptions);    Amap.movecamera (CAMERAUPDATEFACTORY.CHANGELATLNG (LATLNG)); }}

Get latitude and longitude on the android side of the gold map

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.