This essay on the Gould map will be a little more,
I. Business description
There are two types of members in the app business, one is the service personnel, the second is the service personnel, mainly realizes the function, carries on the localization to the service personnel position in the app constantly, then through the service personnel log in the app to provide a latitude and longitude to calculate the service personnel and the service personnel Distance Unit m.
Here is the entire detailed process, from the creation of the German counterpart application (I will not say this here)------finally complete this feature.
Second, create a servlet corresponding to the German map application, create their own Cloud Chart database table
Registered account after the login click on the upper right corner of the console, will appear below this interface, I screenshot
Here, of course, I have registered the interface, if not registered in a button to get key, here you directly, you can create your application, the application name casually take, because we are here a servlet to deal with
Related to the business, so the option for the Web Service API, where you click to get key will appear below the screenshot
This step is done, and then we can go to create the cloud chart we want, enter the console, select the mouse to move to my data, and then select the following Data Management Console (WEB) to add the cloud graph interface
Here is the screenshot after the entry, this screenshot is finished I directly use the text to explain.
The above screenshot is I create good results, here we need to first click on the upper right corner of the data template download, the template download down, modify the corresponding data, add the fields you need, and then click the new map will
The modified template imported into the Cloud Gallery, this template is actually an Excel exported database table. I'll just intercept the table I created, add two fields to the table, and set a field to the Index field.
Remember that the Red field name must be retained (the content can be arbitrarily modified), which is the system template, the following two black fields are added to their own, you can modify, even if you upload it to the Gao Deiuntu server can also be changed.
After uploading the above table, before you open it. Data Management (WEB) will appear before a map of the interface, the left side of a map box appears, you point in, you can see the details of your uploading personnel, as well as by uploading the latitude and longitude of the map displayed on the yellow Pentagram logo. Here's a screenshot.
The field shown in this table is I have modified, not just uploaded in Excel, click on the title of the column can be a series of settings, this I do not say in detail,
Just say the setting of the Index field,
When I go in, I choose to filter the sort index--> a filter sort index is to set a filter condition on the user's own newly added fields.
I use here is the image above the screenshot of the user type, its role I also give you cut down the picture.
To this step we create the entire cloud and upload the steps are complete ... Next I'll talk about the method called.
Second, the servlet query Cloud Image Library Request method
1, first affixed to the developer document address:
http://lbs.amap.com/yuntu/reference/cloudsearch/, I suggest I take a look at it.
The servlet uses the cloud Retrieval API, where the app uses the cloud storage API, and perhaps tomorrow will add an article about how the iOS client corresponds to this interface.
The following is a concatenation of the URL format, directly in the URL to enter a refresh can be get way to obtain the relevant data.
Http://yuntuapi.amap.com/datasearch/local?tableid=568bd32b305a2a31f604c650&city= Beijing &keywords=%20& Filter=type: Service personnel limit=15&page=1&key=? (Here's the parameter key these are your own)
The following is the encapsulated request method code
Package Helper;
Import Java.io.BufferedReader;
Import java.io.IOException;
Import Java.io.InputStreamReader;
Import Java.io.PrintWriter;
Import java.io.UnsupportedEncodingException;
Import Java.net.URL;
Import java.net.URLConnection;
Import java.util.List;
Import Java.util.Map; public class HttpRequest {/** * request to send a GET method to the specified URL * * @param URL * Send the requested URL * @param param *
Request parameter, the request parameter should be the form of name1=value1&name2=value2.
* @return The response result of the remote resource represented by the URL/public static string Sendget (string URL, string param) {String results = "";
BufferedReader in = null;
try {String urlnamestring = URL + '? ' + param;
URL realurl = new URL (urlnamestring);
The connection between open and URL urlconnection connection = Realurl.openconnection ();
Sets the common request attribute Connection.setrequestproperty ("accept", "*/*");
Connection.setrequestproperty ("Connection", "keep-alive"); Connection.setrequestproperty ("User-agent", "MOZILLA/4.")0 (compatible; MSIE 6.0; Windows NT 5.1;
SV1) ");
Establish the actual connection connection.connect ();
Gets all response header fields Map<string, list<string>> Map = Connection.getheaderfields ();
Iterate through all the response header fields for (String Key:map.keySet ()) {System.out.println (key +---> + map.get (key)); }//define BufferedReader input stream to read URL response in = new BufferedReader (New InputStreamReader Connection.getinpu
Tstream ()));
String Line;
while (line = In.readline ())!= null) {result + = line; The catch (Exception e) {System.out.println ("Send GET request exception!
"+ e);
E.printstacktrace ();
///Use finally block to close the input stream finally {try {if (in!= null) {in.close ();
} catch (Exception E2) {e2.printstacktrace ();
} return result; /** * Request * Send the Post method to the specified URL * * @param URL * Send the requested URL * @param param * Request parameters, request parameters should be name1 =value1&nameThe form of 2=value2.
* The response result of the remote resource represented by the @return/public static string Sendpost (string url, string param) {printwriter out = null;
BufferedReader in = null;
String result = "";
try {URL realurl = new URL (URL);
The connection between open and URL URLConnection conn = realurl.openconnection ();
Sets the common request attribute Conn.setrequestproperty ("accept", "*/*");
Conn.setrequestproperty ("Connection", "keep-alive"); Conn.setrequestproperty ("User-agent", "mozilla/4.0" (compatible; MSIE 6.0; Windows NT 5.1;
SV1) ");
The Send POST request must be set to the following two lines conn.setdooutput (true);
Conn.setdoinput (TRUE);
Gets the output stream of the URLConnection object = new PrintWriter (Conn.getoutputstream ());
Send request parameter out.print (param);
Flush output Stream Buffer Out.flush ();
Defines the response of the BufferedReader input stream to read the URL in = new BufferedReader (New InputStreamReader (Conn.getinputstream ()));
String Line;
while (line = In.readline ())!= null) { result + = line; The catch (Exception e) {System.out.println ("send POST request exception!)"
"+e);
E.printstacktrace ();
///Use finally block to turn off output stream, input stream finally{try{if (out!=null) {out.close ();
} if (In!=null) {in.close ();
} catch (IOException ex) {ex.printstacktrace ();
} try {result= new String (Result.getbytes ("iso8859-1"), "UTF-8");
catch (Unsupportedencodingexception e) {//TODO auto-generated catch block E.printstacktrace ();
return result;
}
}
Here is the request method
String Mapparameter=new string ("Tableid=568bd32b305a2a31f604c650&city= Beijing &keywords=%20&filter=type: Massage therapist limit=15&page=1&key=? "). GetBytes ("Iso8859-1"), "UTF-8");
String returnresult=httprequest.sendpost ("http://yuntuapi.amap.com/datasearch/local", Mapparameter);
OUT.PRINTLN ("<script> alert (" +returnresult+ ");</script>");
The filter criteria we query here are the fields we created ourselves (and it was set to the indexed field) Type: Massage Therapist------------------The fields in front of the _updatetime are the data in our database, The following are the real data that is queried through the longitude and latitude, but when used in real use, these data are added to the app, and the app also needs to pass the name of the current location to the servlet, so the data here is wrong.
Three, the servlet calculates the distance between two latitude and longitude degree
This is where the servlet calculates the distance between the service and the staff by latitude, which is actually a one-to-many relationship. A person who is being serviced can correspond to n a service provider. The location of the service personnel will be to match all the inquiries out of the latitude and longitude of the service staff to calculate the distance.
The following method of calculating distances, this is a common method for each large map is applicable.
public static double getdistance (latlng start,latlng end) {
double lat1 = (math.pi/180) *start.latitude;
Double lat2 = (math.pi/180) *end.latitude;
Double lon1 = (math.pi/180) *start.longitude;
Double lon2 = (math.pi/180) *end.longitude;
Double R = 6371;
Double d = Math.acos (Math.sin (LAT1) *math.sin (LAT2) +math.cos (LAT1) *math.cos (LAT2) *math.cos (lon2-lon1)) *r;
return d*1000;
}
LATLNG You can create a class yourself that contains two fields, all of which are of type double. A representation of precision, a representation of latitude.
The process generated by using this method: When the user opens the app interface of the service person, requests the interface that reads the service personnel list, this time the servlet needs to inquire the service personnel information in the High German cloud picture, may limit the query number, then inquires out, The latitude and longitude of each data in the loop and the latitude and longitude in the app interface are calculated by the service personnel, and the relative distance is computed. Tomorrow may be released an iOS essay, on the corresponding interface, mainly posted on the iOS implementation of the time to locate the code of the Cloud map database.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.