Java servlet mobile App Access Interface (iii) Gold map cloud storage and retrieval

Source: Internet
Author: User
Tags cos finally block sin

This essay on the German map will be a bit more,

I. Description of the Business

corresponding There are two types of members in the app business, one is service personnel, the other is the service personnel, the main realization function, the service personnel location in the app is always located, and then through the service personnel log in to the app provided by a latitude and longitude to calculate the distance between the service personnel and the service Unit m.

Here is the entire detailed process, from the creation of the German counterpart (I won't say it here)------finally complete this function.

Create your own cloud database table by creating a map application corresponding to the servlet

Register account after login Click on the top right corner of the console, will appear below this interface, I

Here of course, I have already registered the interface, if not registered in a button to get key, here you go directly into, you can create your app, the application name casually take, because we are here servlet to deal with

Related to the business, so the option for Web Services API, here you click Get Key will appear below

After this step, we can go to create the cloud diagram we want, go to the console, select the mouse to move to my data, and then select the following Data Management Desk (WEB) into the Add Cloud diagram interface

Below is entered after, this is finished I directly use the text explanation.

The above is the result of my creation, here we need to click on the top right of the data template download, the template after downloading, modify the corresponding data, add their own required fields, and then click the new map will

After the modified template is imported into the Cloud Gallery, this template is actually an Excel exported database table. Now I'm just going to intercept the table I created, I've added two fields to the table, and I've set a field as an indexed field.

Remember the red field name must be preserved (the content can be arbitrarily modified), that is the system template comes with, the following two black fields are their own additions, can be arbitrarily modified, even if you upload it to the Gao Deiuntu server can be changed.

After uploading the above table, you can open the previous data management (WEB) before the interface of a map, a map box on the left appears, you click in, you can see the details of the person you uploaded, as well as the upload of latitude and longitude on the map to display the yellow Pentagram logo. Below are

The fields shown in this table are the one I modified, not the one I just uploaded in Excel, and the title in the column can be set in a series of settings, which I will not say in detail,

Just say the settings for the indexed fields,

When I go in, I choose to filter the sort index--filter sort Index to set a filter on the user's own newly added field.

I am using the user type in the above cloud image, and I will give you the function of it.

In this step we create the entire cloud and upload the steps to complete ... Next I'll talk about the method called.

Second, the servlet Query Cloud Library Request method

1, first paste the developer document address:

http://lbs.amap.com/yuntu/reference/cloudsearch/ , I suggest I take a look at it.

Here the servlet uses the cloud retrieval API, and the app uses the cloud storage API, and perhaps tomorrow will add an article about the location of the iOS client that corresponds to this interface.

The following is the concatenation of the URL format, directly in the URL to enter the refresh can get the relevant data get way.

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

 PackageHelper;ImportJava.io.BufferedReader;Importjava.io.IOException;ImportJava.io.InputStreamReader;ImportJava.io.PrintWriter;Importjava.io.UnsupportedEncodingException;ImportJava.net.URL;Importjava.net.URLConnection;Importjava.util.List;ImportJava.util.Map; Public classHttpRequest {/*** A request to send a GET method to a specified URL *@paramURL * URL to send request *@paramparam * Request parameters, request parameters should be in the form of name1=value1&name2=value2. * @returnThe response result of the remote resource represented by the URL*/     Public Staticstring sendget (string url, string param) {string result= ""; BufferedReader in=NULL; Try{String urlnamestring= URL + "?" +param; URL Realurl=NewURL (urlnamestring); //opening and linking between URLsURLConnection connection =realurl.openconnection (); //to set common request propertiesConnection.setrequestproperty ("Accept", "*/*"); Connection.setrequestproperty ("Connection", "keep-alive"); Connection.setrequestproperty ("User-agent",                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) "); //establish an actual connectionConnection.connect (); //Get all response header fieldsmap<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)); }            //defines the response of the BufferedReader input stream to read the URLin =NewBufferedReader (NewInputStreamReader (Connection.getinputstream ()));            String Line;  while(line = In.readline ())! =NULL) {result+=Line ; }        } Catch(Exception e) {System.out.println ("Send GET request exception!" " +e);        E.printstacktrace (); }        //Use the finally block to close the input stream        finally {            Try {                if(In! =NULL) {in.close (); }            } Catch(Exception E2) {e2.printstacktrace (); }        }        returnresult; }    /*** Request to send the Post method to the specified URL * *@paramURL * URL to send request *@paramparam * Request parameters, request parameters should be in the form of name1=value1&name2=value2. * @returnThe response result of the remote resource represented*/     Public Staticstring sendpost (string url, string param) {PrintWriter out=NULL; BufferedReader in=NULL; String result= ""; Try{URL Realurl=Newurl (URL); //opening and linking between URLsURLConnection conn =realurl.openconnection (); //to set common request propertiesConn.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 linesConn.setdooutput (true); Conn.setdoinput (true); //gets the output stream corresponding to the URLConnection objectout =NewPrintWriter (Conn.getoutputstream ()); //Send Request Parametersout.print (param); //buffer for flush output streamOut.flush (); //defines the response of the BufferedReader input stream to read the URLin =NewBufferedReader (NewInputStreamReader (Conn.getinputstream ()));            String Line;  while(line = In.readline ())! =NULL) {result+=Line ; }        } Catch(Exception e) {System.out.println ("Send POST Request exception!" "+e);        E.printstacktrace (); }        //Use the finally block to close the output stream, input stream        finally{            Try{                if(out!=NULL) {out.close (); }                if(in!=NULL) {in.close (); }            }            Catch(IOException ex) {ex.printstacktrace (); }        }               Try{result=NewString (Result.getbytes ("iso8859-1"), "UTF-8"); } Catch(unsupportedencodingexception e) {//TODO auto-generated Catch blockE.printstacktrace (); }        returnresult; }    }

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 condition we are querying here is the field we created ourselves (and it was set up as an indexed field) type: Masseuse------------------the previous fields in the _updatetime above are the data in our database, The back is through the longitude and latitude to query out the real data, but when the actual use, the data are added to the app side, and the app also need to pass the current location of the city name to the servlet, so the data here is wrong.

Second, the servlet calculates the distance between two latitude and longitude,

This is where the servlet calculates the distance between the service staff and the service staff by latitude, which is actually a one-to-many relationship. A person who is serviced by a service person can correspond to n service providers. The location of the service personnel in the latitude and longitude will match all the query out of the service staff latitude and longitude, calculate the distance.

The following method of calculating distance, this is a common method of the major maps are applicable.

  Public Static Doublegetdistance (latlng start,latlng end) {DoubleLAT1 = (math.pi/180) *Start.latitude; DoubleLAT2 = (math.pi/180) *End.latitude; DoubleLon1 = (math.pi/180) *Start.longitude; DoubleLon2 = (math.pi/180) *End.longitude; DoubleR = 6371; DoubleD = Math.acos (Math.sin (LAT1) *math.sin (LAT2) +math.cos (LAT1) *math.cos (LAT2) *math.cos (lon2-lon1)) *s; returnd*1000; }  

LATLNG in Parameters you can create a class yourself that contains two fields that are double types. One represents the precision, one represents the latitude.
The process of using this method: When the user opens the Service personnel's app interface, requests the interface which reads the service personnel list, this time the servlet needs to inquire the service personnel information inside the high-German cloud picture, may limit the query number, then inquires out, The latitude and longitude in each data loop and the latitude and longitude used by the service personnel to open the app interface are matched to calculate the relative distance. Tomorrow may be released an essay on iOS, corresponding to this interface, mainly posted on iOS implementation of the constant location of the cloud map database code

Java servlet mobile App Access Interface (iii) Gold map cloud storage and retrieval

Related Article

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.