There will be more essays about Gaode Map.
1. Business description
There are two types of members in the corresponding APP business: one is the service personnel and the other is the service personnel. It mainly realizes the functions and locates the location of the service personnel in the APP in a timely manner. Then, the distance unit m between the service personnel and the service personnel is calculated through a latitude and longitude provided when the service personnel logs into the APP.
The following is the entire detailed process, from creating a Gaode corresponding application (I won’t talk about it if you register here)-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2. Create the Gaode map application corresponding to the servlet and create your own cloud map database table
After registering an account, log in and click on the console in the upper right corner. The following interface will appear. I took a screenshot.
Of course, this is the interface that I have registered. If you don’t register, just get the key. Click here directly to create your application. You can get the application name at will, because we are servlets here to handle it.
Related business, so the option is the Web Service API. Here you click to get the key and the screenshot below will appear.
After this step is completed, we can create the cloud chart we want, enter the console, select the mouse to move to my data, and then select the data management station (Web) below to enter the interface to add cloud charts.
Below is a screenshot after entering. After this screenshot, I will explain it directly in text.
The screenshot above is the result I created. Here we need to first click on the data template download in the upper right corner. After downloading the template, modify the corresponding data, add the fields you need, and then click on the new map to
The modified template is imported into the cloud library. This template is actually a database table exported by EXCEL. Below I directly intercept the table I created. I added two fields to this table and set one field to the index field.
Remember that the red field name must be preserved (the content can be modified at will), which is included in the system template. The two black fields at the end are added by themselves and can be modified at will. Even if you upload it to the Gaode Cloud Map server, it can be changed.
After uploading the table above, you will open the previous data management (WEB) and the interface of the previous map will appear. A map block appears on the left. Click in and you will see the detailed information of the person you uploaded, as well as the yellow five-pointed star logo displayed on the map through the uploaded latitude and longitude. There are screenshots below
The fields displayed in this table are modified by me, not uploaded in Excel just now. Clicking on the title in the column can make a series of settings. I won't go into details.
Just talk about the settings of the index field.
After entering, I chose to filter the sort index-->Filter the sort index is to set a filter condition for the newly added fields of the user.
I am using the user type taken in the cloud image above. I will also take a picture of it for you.
At this point, we will complete the entire cloud map creation and uploading steps. . . Next I will talk about the method called.
2. Request method for servlet query cloud image library
1. First post the developer's document address:
http://lbs.amap.com/yuntu/reference/cloudsearch/ I suggest you check it out myself
Here, the servlet uses the cloud retrieval API, and the corresponding APP uses the cloud storage API. Maybe tomorrow, an article on the time-location of the IOS client corresponding to this interface will be added.
Below is the spliced URL format. Enter refresh directly into the URL to get the relevant data by GET.
http://yuntuapi.amap.com/datasearch/local?tableid=568bd32b305a2a31f604c650&city=Beijing&keywords=%20&filter=type: Service staff limit=15&page=1&key=? (The parameters KEY here are all your own)
Below 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.URL;import java.net.URLConnection;import java.util.List;import java.util.Map;public class HttpRequest { /** * Send the GET method request to the specified URL* * @param url * URL to send the request * @param param * Request parameters, the request parameters should be in the form of name1=value1&name2=value2. * @return URL Response result of the remote resource represented by the remote resource*/ public static String sendGet(String url, String param) { String result = ""; BufferedReader in = null; try { String urlNameString = url + "?" + param; URL realUrl = new URL(urlNameString); // Open the connection between the URL URLConnection connection = realUrl.openConnection(); // Set the general 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)"); // Create an actual connection connection.connect(); // Get all response header fields Map<String, List<String>> map = connection.getHeaderFields(); // traverse all response header fields for (String key : map.keySet()) { System.out.println(key + "--->" + map.get(key)); } // Define the BufferedReader input stream to read the URL's response in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line; while ((line = in.readLine()) != null) { result += line; } } catch (Exception e) { System.out.println("Exception occurred when sending a GET request!" + 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; } /** * Send a request to the specified URL * @param url * URL to send the request * @param param * Request parameter, the request parameter should be in the form of name1=value1&name2=value2. * @return Response result of the remote resource represented by */ public static String sendPost(String url, String param) { PrintWriter out = null; BufferedReader in = null; String result = ""; try { URL realUrl = new URL(url); // Open the connection between URLConnection conn = realUrl.openConnection(); // Set the general 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)"); // To send a POST request, you must set the following two lines to conn.setDoOutput(true); conn.setDoInput(true); // Get the output stream corresponding to the URLConnection object out = new PrintWriter(conn.getOutputStream()); // Send the request parameter out.print(param); // Buffer out.flush() of the flush output stream; // Define the BufferedReader input stream to read the response of the URL in = new BufferedReader( new InputStreamReader(conn.getInputStream())); String line; while ((line = in.readLine()) != null) { result += line; } } catch (Exception e) { System.out.println("Exception occurred when sending a POST request!" +e); e.printStackTrace(); } //Use finally blocks to close the output stream and the 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; } }The following is the request method
String mapParameter=new String("tableid=568bd32b305a2a31f604c650&city=Beijing&keywords=%20&filter=type: masseur 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 filtering condition we query here is the field we created ourselves (and we set it to an index field) type: Massager --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3. Servlet calculates the distance between two latitudes and longitudes
This is the distance between the servlet and the service personnel through latitude and longitude. This is actually a one-to-many relationship. One person being served can correspond to N people providing services. The latitude and longitude of the service personnel located at the location will match the latitude and longitude of all the service personnel found this time and calculate the distance.
The following is a method of calculating distance. This is a common method that applies to all major maps.
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 in the parameter You can create a class yourself, which contains two fields that are of double type. One represents precision and the other represents latitude.
The process generated by using this method: When the user opens the APP interface of the service personnel, he requests the interface to read the list of the service personnel. At this time, SERVLET needs to query the service personnel information in the Gaode Cloud map once. You can limit the number of queries, and then query them. The latitude and longitude in each data are looped and the latitude and longitude transmitted by the APP interface that is opened by the service personnel, and calculate the relative distance. I may publish an IOS essay tomorrow, which corresponds to this interface, mainly posted on the code of the time-location cloud map database implemented on IOS.
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.