Learning to write interface callbacks

Source: Internet
Author: User
Tags reverse geocoding

When do Baidu map anti-geocoding (coordinates to address),

You need to write a result interface callback, usually in the network request, click the event, as well as some asynchronous operation, need to use the interface callback.

Position Manager, there is a position monitoring:

/*** Write your own location Manager * Created by XHJ on 16-1-27.*/ Public classTrackerlocationmanager {protectedTrackerlocationmanager () {}/*** Example of location Manager*/    Private StaticTrackerlocationmanager instance;  Public StaticTrackerlocationmanager getinstance () {if(Instance = =NULL) {instance=NewTrackerlocationmanager (); }        returninstance; }    /*** Reverse geo-coded monitoring*/     Public InterfaceTrackergeocoderlistener {/**to be replicated, get the results of the anti-geocoding*/        voidGetResult (reversegeocoderesult result); }    /*** Reverse geo-coded monitoring*/Trackergeocoderlistener Trackerlistener; /*** Set up reverse code monitoring*/     Public voidSettrackergeocoderlistener (Trackergeocoderlistener listener) { This. Trackerlistener =Listener; }    /*** Get inverse = geocoding Results * *@paramlatlng latitude and longitude *@return     */     Public voidgetpicaddress (latlng latlng) {GeoCoder Msearch=geocoder.newinstance (); /**geo-coded retrieval listener*/        FinalOngetgeocoderresultlistener listener =NewOngetgeocoderresultlistener () { Public voidOngetgeocoderesult (geocoderesult result) {} @Override Public voidOngetreversegeocoderesult (reversegeocoderesult result) {if(Result = =NULL|| Result.error! =SearchResult.ERRORNO.NO_ERROR) {                    //No search results foundLOG.D ("Alan", "No results retrieved--reverse")); } Else {                    //Get reverse geocoding resultsTrackerlistener.getresult (Result),//Executes the GetResult method into the listener and executes the GetResult method to the subclass}            }        };        Msearch.setongetgeocoderesultlistener (listener); Msearch.reversegeocode (Newreversegeocodeoption (). Location (LATLNG));//Perform reverse coding,Getting results in Ongetreversegeocoderesult
} }

This is another class in which the invocation of a method that obtains a reverse geocoding and the implementation of an interface

Trackerlocationmanager Trackerlocationmanager = trackerlocationmanager.getinstance ();            Trackerlocationmanager.settrackergeocoderlistener (Mygeocoderlistener);            Trackerlocationmanager.getpicaddress (Latlist.get (j));//Get Reverse geocoding

Learning to write interface callbacks

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.