The use of German map, Baidu map use experience

Source: Internet
Author: User
Tags border color

1. Environment Configuration
Gold development positioning, map, search, overlay, these four functions only need to do three
First, download three rack package, Gaodri surface does not involve 3d map No. So file, only need three rack package, for we do not need the function of other racks can not download, such as do not involve navigation we do not need to download the Navigation rack package, this can reduce the load of the application, will download a good rack package into the project, with!
This is part of the project
After the guide package is complete and then the service is added, first, declare the service component in the application tag, each with its own separate location service.<service android:name="com.amap.api.location.APSService"></service>
And then<!--for network positioning--
<uses-permission android:name= "Android.permission.ACCESS_COARSE_LOCATION" ></uses-permission>
<!--for access to GPS location--
<uses-permission android:name= "Android.permission.ACCESS_FINE_LOCATION" ></uses-permission>
<!--get carrier information to support interfaces that provide operator information--
<uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE" ></uses-permission>
<!--used to access WiFi network information, WiFi information is used for network location--
<uses-permission android:name= "Android.permission.ACCESS_WIFI_STATE" ></uses-permission>
<!--this permission to get access to WiFi, WiFi information is used for network location--
<uses-permission android:name= "Android.permission.CHANGE_WIFI_STATE" ></uses-permission>
<!--for network access, network targeting requires internet--
<uses-permission android:name= "Android.permission.INTERNET" ></uses-permission>
<!--to read the current state of the phone--
<uses-permission android:name= "Android.permission.READ_PHONE_STATE" ></uses-permission>
<!--write to the extended storage, write data to the expansion card for write cache location data--
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE" ></uses-permission>

Last set key, add the application tag

<meta-data android:name="com.amap.api.v2.apikey" android:value="key">//开发者申请的key      </meta-data>

2. Function Realization
Finally, the code implements the function we want.
The first step is to initialize the AMAP class, which is a map object with many maps operating methods and interfaces.

privatevoidinit() {        ifnull) {            aMap = mapView.getMap();            aMap.moveCamera(CameraUpdateFactory.zoomTo(16));//设置地图的缩放比例            setUpMap();        }    }

Some properties of the map object are initialized after getting the map object

private void Setupmap () {//Custom system positioning small blue dot mylocationstyle mylocationstyle = new Mylocationstyle ();Mylocationstyle. Mylocationicon(com. AMAP. API. Maps2d. Model. Bitmapdescriptorfactory                . Fromresource(R. drawable. Biaozhi));//Set a small blue dot iconMylocationstyle. Strokecolor(Color. White);//Set the border color of the circleMylocationstyle. Radiusfillcolor(Color. ARGB(0,0,0,0));//Set the fill color of the circleMylocationstyle. Strokewidth(0.0F;//Set the border thickness of the circle */AMap. Setmylocationstyle(Mylocationstyle);AMap. Setlocationsource(this);//Set Location monitoringAMap. Getuisettings(). setmylocationbuttonenabled(true);//sets whether the default positioning button is displayedAMap. setmylocationenabled(true);//Set to TRUE indicates that the positioning layer is displayed and can trigger positioning, false means hide the location layer and cannot trigger the positioning, default is false*/}        });}

Run an interface method that activates the location, and start positioning

/** * Activate location * /    @Override     Public void Activate(Onlocationchangedlistener Listener) {Mlistener = listener;if(Mlocationclient = =NULL) {mlocationclient =NewAmaplocationclient ( This); Mlocationoption =NewAmaplocationclientoption ();//Set Location monitoringMlocationoption.setneedaddress (true); Mlocationoption.setoncelocation (true); Mlocationclient.setlocationlistener ( This);//Set to high precision positioning modeMlocationoption.setlocationmode (AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);//Set positioning parametersMlocationclient.setlocationoption (mlocationoption);//This method initiates a location request every fixed time, in order to reduce power consumption or network traffic consumption,            //Note Set the appropriate location time interval (minimum interval support is 2000ms), and call the Stoplocation () method at the appropriate time to cancel the location request            Call the OnDestroy () method at the appropriate life cycle after the positioning is complete            //In the case of a single position, no need to call the Stoplocation () method to remove the request if the location is successful or not, the location SDK will be removed from the insideMlocationclient.startlocation (); }    }

After the positioning is successful, it will callback the positioning successful interface method, where we can get to our location after the city, latitude, and many

 /** * Callback function after successful positioning * /@Override public void onlocationchanged (Amaplocation amaplocation) {if (Mlistener! = null && Amaplocati on = null) {if (amaplocation! = null && amaplocation. GetErrorCode() ==0) {Mlistener. onlocationchanged(amaplocation);//display system small blue dotAMap. Addmarker(Newcom. AMAP. API. Maps2d. Model. Markeroptions(). Anchor(0.5F0.5F. Icon(com. AMAP. API. Maps2d. Model. Bitmapdescriptorfactory                                . Frombitmap(bitmapfactory. Decoderesource(Getresources (), R. drawable. Biaozhi))). Position(Newcom. AMAP. API. Maps2d. Model. LATLNG(amaplocation. Getlatitude(), Amaplocation. Getlongitude())));Log. E("5555", amaplocation. Getprovince()+","+amaplocation. Getcity()+","+amaplocation. GetAddress()+","+amaplocation. Getstreet()+","+amaplocation. Getaoiname());City=amaplocation. Getcity();Lp=new Latlonpoint (amaplocation. Getlatitude(), Amaplocation. Getlongitude());Poi_search ("");//start around search} else {String Errtext ="Location failed,"+ amaplocation. GetErrorCode()+": "+ amaplocation. GetErrorInfo();Log. E("Amaperr", Errtext);}        }    }

After rent is the surrounding search code:

private void Poi_search (String str) {com. AMAP. API. Services. Poisearch. Poisearch. QueryMpoisearchquery = newcom. AMAP. API. Services. Poisearch. Poisearch. Query(STR,"", city);Mpoisearchquery. Requiresubpois(true);Mpoisearchquery. SetPageSize( -);Mpoisearchquery. Setpagenum(0);        com. AMAP. API. Services. Poisearch. PoisearchPoisearch = newcom. AMAP. API. Services. Poisearch. Poisearch(baidumapactivity. this, Mpoisearchquery);Poisearch. Setbound(Newcom. AMAP. API. Services. Poisearch. Poisearch. Searchbound(LP, the, true));Poisearch. Setonpoisearchlistener(this);Poisearch. Searchpoiasyn();}

After successful search, call callback interface method to get the results we searched for.

 @Override    public void onPoiSearched(com.amap.api.services.poisearch.PoiResult poiResult, int i) {        poiItems=poiResult.getPois();        listView.setAdapter(new BaiDuListAdapter(BaiDuMapActivity.this,poiItems));    }

Finally, we deal with the results of the search.
The last function is to add a cover

AMap. Addmarker(Newcom. AMAP. API. Maps2d. Model. Markeroptions(). Anchor(0.5F0.5F. Icon(com. AMAP. API. Maps2d. Model. Bitmapdescriptorfactory                                . Frombitmap(bitmapfactory. Decoderesource(Getresources (), R. drawable. Biaozhi))). Position(Newcom. AMAP. API. Maps2d. Model. LATLNG(latitude, longitude)));

Add our red flag to the map based on latitude and longitude so that users know their current location well.
3. The difference between Baidu and German
100-degree 2d maps need to add. so files and no need to
200 degrees does not support the keyword is empty point of interest search and gold can

The use of German map, Baidu map use experience

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.