Insert Baidu Map SDK in Android---project

Source: Internet
Author: User

Baidu Map

The app comes with a map soufun

    1. Download the SDK of Baidu map familiarize yourself with the API Handbook Baidu Developer's account
    2. 2.12 just have to have an AK to be able to build the application's package name and signature return the developer's serial number
Use Baidu Map steps
    1. Application API Key
    2. Create Project
    3. Reference Library Armeabi only compatible with Arme CPU
    4. Networking permissions
    5. Initialize the map engine (2.13 is initialized in the code, the high version is configured in the manifest file)
    6. referencing layouts
Mapview Show Map V

Inherit ViewGroup own definition control specifically for displaying maps

1. MapController    getController()   获取到地图的控制器 2.  让mapView的生命周期 必须和anctivity绑死在一起  onResume onPause destroy3.  setBuiltInZoomControls(boolean on)   设置是否启用内置的缩放控件回调 MKMapViewListener
Bmapmanager M

Ability to initialize the map engine

1. destroy()  当程序退出的时候调用2. start()  当程序可见的时候调用3. stop()  当程序不可见的时候调用 4. init(String strKey, MKGeneralListener listener) 方法校验key信息, 回调
Mapcontroller Map Controller C

Operations that specifically control the map

1. animateTo(GeoPoint point)   移动到指定位置2. setCenter(GeoPoint point)  在给定的中心点GeoPoint上设置地图视图。3. setZoom(float zoomLevel)  设置地图的缩放级别4.  缩放5.  旋转6.  改动鸟瞰角度
Layer
1. 卫星图层 mapView.setSatellite(true); 2. 交通图层 mapView.setTraffic(true);
Covering material
Cover contains: Abstract base class of covering: Overlay (Core Class) Geometry: Graphicsoverlay text: Textoverlay category entry: Itemizedoverlay Local search: Poioverlay Route planning: Routeoverlay Change route: Transitoverlay My location: Mylocationoverlay step: * 1. Get the overlay on the map list<overlay> o    Verlays = Mapview.getoverlays ();     * 2. Create a new overlay geometry graphicsoverlay, text textoverlay, multiple entries (detailed implementation below) * 3. Get the overlay on the map to add a new overlay overlays.add (overlay);    * 4. Refresh map Mapview.refresh (); * Graphicsoverlay:graphicsoverlay overlay = new Graphicsoverlay (Mapview);  Descriptive narrative a set of graphics Geometry arg0=new Geometry ();  Shape of the graph arg0.setcircle (point, 1000);  Number of participants 1, center number 2, RADIUS unit (m) symbol arg1 = new symbol ();    The style of the graphic symbol.color color = new Symbol (). New color ();    color.alpha=155;    color.red=100;    color.blue=200;    color.green=0;    Sets the style of the graphic arg1.setsurface (color, 1, 1);    Graphic graphic=new Graphic (arg0, arg1);    Draw Overlay.setdata (graphic); * Textoverlay textoverlay overlay=new textoverlay (Mapview); //Draw Textitem Item=new Textitem ();    item.align=textitem.align_center;//Center Alignment item.pt=point;//Let the text display in the Dark Horse this position item.fontsize=14;    Item.fontcolor=getcolor ();    item.text= "Dark Horse program Ape"; Overlay.addtext (item); * Itemizedoverlay itemizedoverlay<overlayitem> itemizedoverlay = new ItemizedOverlay<        Overlayitem> (Getresources (). Getdrawable (R.drawable.eat_icon), Mapview) {//entries for click events!!!            @Override protected Boolean onTap (int index) {Overlayitem item = getItem (index);            GeoPoint point = Item.getpoint (); Update the location of the view bubble (previously initialized) Mapview.updateviewlayout (pop, new Mapview.layoutparams (layoutparams .            Wrap_content, Layoutparams.wrap_content, point, MapView.LayoutParams.BOTTOM_CENTER));            Pop.setvisibility (view.visible);//Let the Bubbles show TextView tv= (TextView) Pop.findviewbyid (r.id.title);                Tv.settext (Item.gettitle ()); String SNIPpet = Item.getsnippet ();//Get descriptive narrative information//Toast.maketext (Getapplicationcontext (), snippet, 0). Show ();    return true;//for Consumption}}; Overlayitem item = new Overlayitem (point, "Dark Horse program Ape", "not 10000 employment does not pay a penny for tuition");//1 coordinates 2 title 3 descriptive narrative Itemizedoverlay.additem (item)    ;    item = new Overlayitem (new GeoPoint (latitude + longitude), "North", "Add latitude");    Itemizedoverlay.additem (item);    item = new Overlayitem (new GeoPoint (latitude, longitude + 1000), "eastward", "Add Longitude");    Itemizedoverlay.additem (item);    item = new Overlayitem (new GeoPoint (latitude-1000, longitude-1000), "Southwest", "reduce latitude and longitude");    Itemizedoverlay.additem (item);    Step 3 Overlays.add (Itemizedoverlay); Step 4 Mapview.refresh (); * Poioverlay: Displays a local overlay after the search, such as the following. * Routeoverlay: The route is displayed after the driving route search, for example the following. * Transitoverlay: Bus transfer route display, example as follows. * Mylocationoverlay: My location covering, for example, below.
Search
* Core classes: Mksearch and Mksearchlistener 1. Mksearch Search API for location search/Peripheral search/Public transport search/range search/Ride search/Walk search 2.    Mksearchlistener search structure will callback to the interface of the method * Rectangle/Circle/The whole city region searching for more interesting points mksearch search = new Mksearch ();    Search.init (Manager,mksearchlistener)///Because there are many methods for this interface, you can use the adapter design mode//first parameter: keyword (like a hotel) the third parameter (the point in the upper-left corner) (the point in the lower-right corner) 1. Search.poisearchinbounds (String key, GeoPoint ptlb, GeoPoint ptrt) rectangular area Search 2. Search.poisearchnearby (String key, GeoPoint pt, int radius) round area search 3.        Search.poisearchincity ("Beijing", "McDonald's");    Search.gotopoipage (index);//Display the next page (a page showing 10) in the Mksearchlistener in the Ongetpoiresult () callback.            public void Ongetpoiresult (mkpoiresult result, int type, int ierror) {if (ierror==0) {//has results            Draw the results to the phone screen (map)//step 1 get to the full cover list<overlay> overlays = Mapview.getoverlays ();            Step 2 Create the cover of the letter Poioverlay overlay=new Poioverlay (Searchinrectactivity.this, Mapview); arraylist<mkpoiinfo> Allpoi = ResULt.getallpoi ();            Overlay.setdata (Allpoi);            Step 3 Add the covering to the previous cover of the Set Overlays.add (overlay);        Step 4 Refresh the interface Mapview.refresh (); }* Drive/bus/walking route search//1 start of the City 2 start location 3 Destination City 4 destination coordinates 1.search.drivingsearch (String startcity, Mkplannode start, St Ring endcity, Mkplannode end)//drive 2.search.transitsearch (String startcity, mkplannode start, Mkplannode end);//Bus 3 . Search.walkingsearch (String startcity, mkplannode start, Mkplannode end);//Walk//    Callback in the Ongetdrivingrouteresult of the Mksearchlistener.        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Mksearch search=new Mksearch ();        Search.init (Manager, New Busadapter ());        Mkplannode start=new Mkplannode ();//Location: Contains location and name Start.pt=point;        Mkplannode end=new Mkplannode ();        End.pt=new GeoPoint (40065796, 116349868);        Search.setdrivingpolicy (Mksearch.ecar_time_first);//Set up a driving planSearch.drivingsearch ("Beijing", Start, "Beijing", end);//drive (Mode 1) search.settransitpolicy (Mksearch.ebus_walk_first);  Search.transitsearch ("Beijing", Start, end); Bus (Mode 2) search.walkingsearch ("Beijing", Start, end); Walk (mode 3)} Private class Busadapter extends mksearchadapter{@Override public void Ongettransitroute                 Result (mktransitrouteresult result, int ierror) {if (ierror==0) {///Here only shows the callback of the bus, drive and walk not written, see project.                Scheme of public transport Mktransitrouteplan plan = Result.getplan (0);                list<overlay> overlays = Mapview.getoverlays ();                Transitoverlay overlay=new Transitoverlay (Busactivity.this, Mapview);                Overlay.setdata (plan);                Overlays.add (overlay);            Mapview.refresh (); }        }    }
Positioning:
* Positioning the Way 1. GPS 2. WiFi 3.    Base station * System Native Location://Call is Google's API, Mars coordinates, inaccurate. Locationmanager lm = (locationmanager) getsystemservice (location_service); * Baidu Map location: Need: liblocsdk.so Locsdk.jar core        Api:locationclient (locationclientoption) Bdlocationlistener public class Mylocationactivity extends Baseactivity {        Public locationclient mlocationclient = null;        callback method public Bdlocationlistener MyListener = new Mylocationlistener ();            @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Mlocationclient = new Locationclient (Getapplicationcontext ()); Declaration Locationclient Class Mlocationclient.registerlocationlistener (MyListener);            Register the Listener function locationclientoption option = new Locationclientoption (); Option.setopengps (TRUE); Turn on the GPS Option.setaddrtype ("all");//The positioning results returned include address information Option.setcoortype ("Bd09ll");//Return of the positioning result is Baidu latitude and longitude, the default        Value gcj02    Option.setscanspan (5000);//Set the time interval for initiating a location request to 5000ms Option.disablecache (true);//disable enabling cache positioning option.se Tpoinumber (5); Returns the maximum number of POI option.setpoidistance (1000); Poi Query Distance Option.setpoiextrainfo (true);        Is there a need for specific information such as POI phone and address mlocationclient.setlocoption (option);            } @Override protected void OnStart () {Super.onstart ();            Mlocationclient.start (); if (Mlocationclient!=null &&mlocationclient.isstarted ()) {mlocationclient.requestlocation ();//Request Location            Position}} @Override protected void OnStop () {super.onstop ();        Mlocationclient.stop ();            The public class Mylocationlistener implements Bdlocationlistener {//is connected to the location @Override                public void Onreceivelocation (bdlocation location) {Double latitude2 = Location.getlatitude (); Double Longitude2 = location.geTlongitude ();                Toast.maketext (Getapplicationcontext (), latitude2+ "..." +longitude2, 0). Show ();                Mylocationoverlay overlay=new Mylocationoverlay (Mapview);                Locationdata data=new locationdata ();                Data.latitude=latitude2;                Data.longitude=longitude2;                Overlay.setdata (data);                Mapview.getoverlays (). Add (overlay);            Mapview.refresh ();        }//received a point of interest around @Override public void Onreceivepoi (Bdlocation arg0) {} }    }

Insert Baidu Map SDK

in Android---project

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.