Gold map gets the latitude and longitude of the center point of the current screen

Source: Internet
Author: User


One of the company's needs is to load nearby merchant information as the screen changes.

So the map gets the latitude and longitude of the center point of the current screen?


Core method: Amap.setoncamerachangelistener (this);


Implementing the interface:

@Override
public void Oncamerachange (cameraposition position) {
LATLNG target = Position.target;
System.out.println (target.latitude + "jinjin------" + target.longitude);
}


<span style= "FONT-SIZE:18PX;" >package Com.amap.map2d.demo.basic; Import Android.app.activity;import Android.os.bundle;import Android.util.displaymetrics;import Com.amap.api.location.core.geopoint;import Com.amap.api.maps2d.amap;import Com.amap.api.maps2d.amap.oncamerachangelistener;import Com.amap.api.maps2d.mapview;import Com.amap.api.maps2d.model.cameraposition;import Com.amap.api.maps2d.model.latlng;import Com.amap.map2d.demo.R; /** * AMapV1 map describes how to display a basic map */public class Basicmapactivity extends Activity implements Oncamerachangelistener {private M Apview mapview;private AMap AMap; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (r.layout.basicmap_activity); Mapview = (Mapview) Findviewbyid (R.ID.MAP); Mapview.oncreate (savedinstancestate);//This method must override Init (); Amap.setoncamerachangelistener (this);} /** * Initialize AMap object */private void init () {if (AMap = = null) {AMap = Mapview.getmap ();}} /** * method must be rewritten */@Overrideprotected void OnresumE () {super.onresume (); Mapview.onresume ();} /** * method must be rewritten */@Overrideprotected void OnPause () {super.onpause (); Mapview.onpause ();} /** * method must be rewritten */@Overrideprotected void onsaveinstancestate (Bundle outstate) {super.onsaveinstancestate (outstate); Mapview.onsaveinstancestate (outstate);} /** * method must be rewritten */@Overrideprotected void OnDestroy () {Super.ondestroy (); Mapview.ondestroy ();} @Overridepublic void Oncamerachange (cameraposition position) {latlng target = Position.target; System.out.println (target.latitude + "jinjin------" + target.longitude);} @Overridepublic void Oncamerachangefinish (cameraposition position) {//TODO auto-generated method stub}}</span>



Results show




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Gold map gets the latitude and longitude of the center point of the current screen

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.