You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.9 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. package com.asset.test;
  2. import java.math.BigDecimal;
  3. import java.net.URLEncoder;
  4. import java.util.HashMap;
  5. import java.util.Map;
  6. import javax.servlet.http.HttpServletRequest;
  7. import org.json.JSONObject;
  8. import org.springframework.http.HttpEntity;
  9. import org.springframework.http.HttpHeaders;
  10. import org.springframework.http.HttpMethod;
  11. import org.springframework.http.ResponseEntity;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RequestMethod;
  14. import org.springframework.web.bind.annotation.RequestParam;
  15. import org.springframework.web.bind.annotation.RestController;
  16. import org.springframework.web.client.RestTemplate;
  17. @RestController
  18. @RequestMapping(value = "/qr-feedback")
  19. public class testRestController {
  20. @RequestMapping(value = "/test/map", method = RequestMethod.GET)
  21. public Map<String, String> testMap(HttpServletRequest request, @RequestParam String locationName) {
  22. String sSearchLocation ="";
  23. //String sTmp = request.getParameter("locname");
  24. String sTmp = locationName;
  25. String sLATITUDE = "";
  26. String sLONGITUDE = "";
  27. if ( sTmp != null && !sTmp.equals("") ) sSearchLocation = sTmp;
  28. System.out.println("sSearchLocation---: "+ sSearchLocation);
  29. String str=request.getParameter("serviceinput");
  30. if (str==null )
  31. {
  32. }
  33. else
  34. {
  35. JSONObject lg = new JSONObject(str);
  36. System.out.println("latitude : "+ lg.get("latitude"));
  37. System.out.println("longitude : "+ lg.get("longitude"));
  38. sLATITUDE =""+ (Double)lg.get("latitude");
  39. sLONGITUDE = ""+ (Double)lg.get("longitude");
  40. }
  41. if ( (sLATITUDE==null || sLATITUDE.equals("")) && ( sLONGITUDE==null || sLONGITUDE.equals("") ) )
  42. {
  43. if (!sSearchLocation.equals("")) {
  44. try{
  45. String urlString ="http://10.1.0.122/geocode_api.php?address="+ URLEncoder.encode( sSearchLocation, "UTF-8" );
  46. System.out.println(urlString);
  47. ResponseEntity<String> response = null;
  48. RestTemplate restTemplate = new RestTemplate();
  49. String bodyMessage = "";
  50. HttpHeaders headers = new HttpHeaders();
  51. try {
  52. HttpEntity<String> postData = new HttpEntity<String>(headers);
  53. response = restTemplate.exchange(urlString, HttpMethod.POST, postData, String.class);
  54. bodyMessage = response.getBody();
  55. //System.out.println("\n bodyMessage" + bodyMessage);
  56. } catch (Exception e) {
  57. e.printStackTrace();
  58. //System.out.print("\n ERROR---: " + e);
  59. bodyMessage = "Error";
  60. }
  61. JSONObject object = new JSONObject(bodyMessage);
  62. if ( (Boolean)object.get("status"))
  63. {
  64. JSONObject dataObject = (JSONObject) object.get("data");
  65. System.out.println("latitude 1 : "+ dataObject.get("latitude"));
  66. System.out.println("longitude 1 : "+ dataObject.get("longitude"));
  67. sLATITUDE = ""+ (BigDecimal)dataObject.get("latitude");
  68. sLONGITUDE = ""+ (BigDecimal)dataObject.get("longitude");
  69. }
  70. }
  71. catch(Exception e)
  72. { System.out.println(e); }
  73. }
  74. else if(request.getParameter("latitude")!=null && request.getParameter("longitude")!=null)
  75. {
  76. sLATITUDE = request.getParameter("latitude");
  77. sLONGITUDE = request.getParameter("longitude");
  78. }
  79. else
  80. {
  81. sLATITUDE = "13.0827";
  82. sLONGITUDE = "80.2707";
  83. }
  84. }
  85. if ( sLATITUDE == null || sLATITUDE.equals("") || sLONGITUDE == null || sLONGITUDE.equals("") )
  86. {
  87. //out.println("<br><br><center><b>No Data Found</b></center>");
  88. System.out.println("Record Not Found");
  89. //return;
  90. }
  91. //String bodyMessage = sLATITUDE;
  92. System.out.println("sLATITUDE---:"+sLATITUDE);
  93. System.out.println("sLONGITUDE---:"+sLONGITUDE);
  94. // JSONObject jsonObj = new JSONObject();
  95. // jsonObj.put("sLATITUDE", sLATITUDE);
  96. // jsonObj.put("sLONGITUDE", sLONGITUDE);
  97. //
  98. // System.out.println("jsonObj :"+jsonObj);
  99. Map<String, String> hasMap = new HashMap<String, String>();
  100. hasMap.put("sLATITUDE", sLATITUDE);
  101. hasMap.put("sLONGITUDE", sLONGITUDE);
  102. return hasMap;
  103. }
  104. }