This article is mainly because recently in the study use Baidu Map, found some problems, share with the others.
1, according to the "Hello World" example of the Android SDK Development Guide, to build a basic map page, if you are exactly as written in the sample code, it is not successful, there will be the following problems error message " java.lang.RuntimeException:Unable to instantiate activity ComponentInfo "
The reason this problem arises is that
In the second step, configure the Activity section with a value of android:name. Mapdemo, and in the fourth step, create a map activity where the activity inherits the class name written by Mymapactivity. If you want to configure activity in Androidmanifest.xml. Mapdemo as the starting activity, in addition to adding the following code between <Activity></Activity>
<intent-filter> <actionandroid:name= "Android.intent.action.MAIN"/> <categoryandroid: Name= "Android.intent.category.LAUNCHER"/></intent-filter>
and the Android:name. Mapdemo change to your current project "package name +mymapactivity" or directly write "mymapactivity", so that the execution will build a basic Baidu map.
This problem is also a basic problem of Android development, but also to my Android dabbler a knowledge point of consolidation. Here is a review of the following points of view for this issue:
(1) Androidmanifest.xml as a project layout file, always grasp the entire project lifeline, when the project starts, to set the Startup items, permissions are insufficient, to add the appropriate permission settings.
(2) How does the activity configured in Androidmanifest.xml relate to the. java files in src? The value of the android:name in the activity that relies on configuration is exactly the same as the class name in the. java file.
(3) and how does the "backstage". java file relate to the activity layout file in the res/layout of the "foreground" (Please allow me to use non-professional terminology such as front and back, because my lord does Web development, so that feels more image)? is through the. java file, in the OnCreate method that inherits the new class of the activity class
Setcontentview (R.layout.activity_main)
Such a statement is done, the activity_main here is the layout file name only.
From a few of the above we will find that the main two things in Android development by name to match, so we must be in the development of a lot of attention in this regard, as to whether other things are also dependent on the name to match, we need to continue in the development of discovery.
2, said the second question is about the coordinates, in the Baidu map gives the source code, we will find similar statements
GeoPoint Point =new GeoPoint ((int) (39.915* 1E6), (int) (116.404* 1E6));
Translation is to create a geopoint type of latitude of 39.915 degrees, longitude 116.404 degrees of coordinate points, why to *1e6, is to put the longitude, latitude into a micro-degree, is on the original basis multiplied by 10-6 power. As for the geopoint in the end is what, that is the Baidu package good, so I also lazy to care about, we know that with the coordinate point on the line.
However, there is a small problem here, that is, we habitually think that the time to write the coordinate point is the format " longitude, Latitude ", and this method of the constructor is completely the opposite. Of course, this is nothing, but the problem is, in the Baidu map is officially given the "Pick coordinate system" tool (Link: http://api.map.baidu.com/lbsapi/getpoint/ Index.html, this east is still very practical, if we do map development without it, that is no, it is the coordinate-address of the query tool, the use of the coordinates of the form is " longitude, Latitude ", a bit of our sense of bias. So easy to mistake, this piece to pay attention to, otherwise the coordinates are 108,000 in the outside.
PS: Longitude (longitude), Latitude (latitude)
3, on the positioning of the SDK, the problem is really deceptive. It was a pity to spend a few hours in the afternoon.
Although the title says Android SDK,
In the Baidu Map official positioning SDK is very detailed, how to build the basic positioning function of the steps have been detailed to us, but there is a small flaw I have to say, reached the point of appalling.
First of all, a brief review of Baidu map official given the east
In the V4.1 version of the 3rd, the use of the function class,3.1.1 Initialization locationclient class subsection
Public locationclient mlocationclient = null;public Bdlocationlistener MyListener = new Mylocationlistener (); Publicvoid onCreate () { mlocationclient = new Locationclient (Getapplicationcontext ()); Declaration Locationclient Class Mlocationclient.registerlocationlistener (MyListener); Register Listener Function}
3.1.3 Setting the positioning Parameters section
locationclientoption option = new Locationclientoption (); Option.setlocationmode (locationmode.hight_accuracy);// Set the positioning mode Option.setcoortype ("Bd09ll");//Return the positioning result is Baidu latitude and longitude, the default value of Gcj02option.setscantype (5000);// Set the time interval for initiating a location request to 5000msoption.setisneedaddress (true);//The location result returned contains address information option.setneeddevicedirect (TRUE);// The returned positioning results include the direction of the phone head mlocclient.setlocoption (option);
On the 4th line of the Setscantype method, please rewrite it into Setscanspan. The error may have been the member method name of the previous version, which no longer exists in this version.
3.1.4 Initiating the location request section
if (mlocclient! = null && mlocclient.isstarted ()) mlocclient.requestlocation (); Else log.d ("LocSDK3", " Locclient is null or not started ");
At first glance, the organization is very clear, first declare the class, binding method, if there are special requirements, and then add an option setting, finally verify that the object is empty, not empty to perform the final request location, how perfect ah! ~
But if we do this, then we will find that the log has been "locclient is null or not started" this sentence, I tried n many times, have a desire to vomit blood (please forgive my spit groove), Finally through the positioning of the SDK sample line to find the problem (the reason for a row of the search, because the project into the local project, a variety of red, not run), the reason is that in the Locationclient class instance call Requestlocation () method, be sure to call the start () method, like this:
Mlocationclient.start ();
Oh ~ ~ What is that? Yes, it's not written in the development Guide. Should be a method to enable the Locationclient instance to start, so the isstarted () in the later if condition sentence we know what's going on.
4. Then say how to successfully run the "baidumap_androidsdk_v2.4.1_sample" sample from the Android SDK locally, this is an official demo showing us the various function modules under the Android SDK.
If you read the Baidu map of the use of rules, we know if we want to use the Baidu Map API, you must apply for the key, and the keys, I summarize the words are in the security code, the following only said Android SDK Security Code composition: Digital Signature +;+ package name .
In fact, this part of the Baidu map application Key "View detailed configuration Method" has been described in detail. I just want to say the package name here, to write the example package name we downloaded: Baidumapsdk.demo.
This might be a logical thing for most friends, and I said it because I first applied for key, and I created a local project and didn't run the sample directly, so I was a little bit confused at the time and mistook the key for my project as a key that could be used on the sample.
This one is erased from the mind without encountering this problem.
With a step-by-step exploration, slowly can follow their own ideas to use Baidu map to design some small functions, but also encountered a number of problems, but feel that the solution is very quick, here is not detailed, are small problems. If you're having problems with other Android SDKs, we can talk about it.
In addition, these days through the Baidu Map API learning, but also to see the gap, their own or to continue to learn, improve themselves, to the degree of Niang.
This article is from the "Give Me a Gener cigarette" blog, please be sure to keep this source http://zhouhongyu1989.blog.51cto.com/2931598/1409723