APICloud (6): positioning using aMapLBS

There are many maps used for positioning in APICloud's module library, such as Baidu and AutoNavi. Here I use AutoNavi map for positioning. The basic process is as follows:

1. Add the "aMapLBS" module to the module of the app ;

 

2. Get the API Key of AutoNavi Map .

a. Go to AutoNavi Open Platform to register a developer account, link: http://lbs.amap.com/

b. Create an application in the AutoNavi open platform: Console--->Application Management---->Create a new application, as shown in the figure:

Fill in the application name at will, and choose a type of application type according to the function of the app, here I am Select "Life".

c. Add a new Key: Select the app you just created, click "Add New Key" on the right, and the pop-up box is as shown below:

Key Name: Name it according to the naming convention, preferably according to the name and function of the next APP.

Service platform: Just write it according to the service platform of the APP, I choose Android here

Release version security code SHA1: This one developed using the APICloud platform is very convenient, because the APICloud platform has already provided it to you. Open APICloud to find the APP that needs to add positioning information, click the overview on the left, as shown in the figure:

After clicking "Overview", you can see less things, and basically you can only see the APP information. Click the ^ in the lower right corner to see more complete, like "appKey", like "Android signature certificate SHA1 code", like "Android package name", these are the good stuff we need.

Copy the "Android Signature Certificate SHA1 Code" in the APICloud project overview to AutoNavi's "Release Security SHA1".

PackageName: The obtaining method is the same as obtaining the SHA1 code. Just copy the "Android Package Name" in the APICloud project overview.

d. to submit

e. After the submission is successful, there will be an additional key information just created below the application, and the API Key acquisition is completed.

 

3. Configure the API Key into the project's config.xml file :

<feature name="aMapLBS">
    <param name="android_api_key" value="f7Is0dWLom2q6rV3ZfFPZ1aa"/>
</feature>

Note : An API key can only correspond to one APP project, and an exception will occur when the same API key is used in multiple APPs.

 

4. The page uses Demo :

/**
 * This event is triggered when the a tag where "Location" is located, and this event is used to locate the current location
 * @param obj: the clicked A tag
 *  **/
function loadPosition(){
	var aMapLBS = api.require('aMapLBS');//Introduce the module
	//Configure location information
	aMapLBS.configManager({
	    accuracy: 'hundredMeters',
	    filter: 1
	}, function (ret, err) {
	    if (ret.status) {	        
			// first cancel other positioning
			aMapLBS.stopUpdatingLocation();
			//First locate the latitude and longitude
			aMapLBS.singleLocation({
	            timeout: 10
            }, function (ret, err) {
            	if (ret.status) {
				   //alert(JSON.stringify(ret));
				   //alert("Longitude: "+ret.lon+"\nLatitude: "+ret.lat);
				   	$("#longitude").val(ret.lon);
				   	$("#latitude").val(ret.lat);				   
		   			//directly locate the address
					aMapLBS.singleAddress({
					    timeout: 10
					}, function(ret2, err2) {
					    if (ret2.status) {
					        //alert(JSON.stringify(ret2));//Get the name of the point of interest
					        var address = ret2.address.AOIName;
					        $("#position").text(ret2.address.AOIName);
					    }
					});	
				}
            });
		
	    }
	});
}

Note : After adding a new module, you need to customize the loader, you can no longer use the system loader, and you can no longer use the previous loader, you need to recompile the custom loader. After recompiling and downloading and installing, it is best to do a "full real machine synchronization". Sometimes an error is still reported after reprogramming and full synchronization (the last time I used it was when calling aMapLBS.singleLocation, ret.status was always false ), you can try to compile it in the cloud (remember to submit all the code that needs to be submitted before compiling in the cloud) Compile After completion, check if there is any problem, and if there is no problem, recompile the custom loader (this is how the problem is solved this time).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326329290&siteId=291194637