LocationControl.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Copyright (c) 2000-2011 by SuperMap Software Co., Ltd.*/
  2. /**
  3. * Class: SuperMap.LocationControl
  4. * 支持安卓定位功能。
  5. */
  6. SuperMap.LocationControl = SuperMap.Class({
  7. /**
  8. * Constructor: SuperMap.LocationControl
  9. * 构造函数。
  10. *
  11. * 例如:
  12. * (start code)
  13. * var control = new SuperMap.LocationControl();
  14. control.local();
  15. * (end)
  16. */
  17. initialize: function() {
  18. },
  19. /**
  20. * Method: local
  21. * 截图。
  22. * Parameters:
  23. * onSuccess - {<Function>} 定位成功回调函数。
  24. * onError - {<Function>} 定位失败回调函数。
  25. * timeOut — {<Number>} 设置GPS定位时等待的时间
  26. */
  27. local: function(onSuccess,onError,timeOut){
  28. var me = this;
  29. var lat,lot,errorInfo;
  30. cordova.exec(
  31. function (location){
  32. lat = location["lat"];
  33. lon = location["lon"];
  34. if(lat == 0 || lon == 0){
  35. errorInfo = location["errorString"];
  36. console.log(errorInfo);
  37. //alert("请确定打开GPS或网络连接正常");
  38. onError("定位失败,请确定打开GPS或网络连接正常。");
  39. }else{
  40. position = new SuperMap.LonLat(lon, lat);
  41. onSuccess(position);
  42. //me.transCoordinate(position.lon,position.lat,onSuccess,onError);
  43. }
  44. },function (e){
  45. },"SMLocation","Location", [timeOut]);
  46. },
  47. /**
  48. * APIMethod: destroy
  49. * 释放资源,将引用资源的属性置空。
  50. */
  51. destroy: function() {
  52. },
  53. CLASS_NAME: "SuperMap.ShotScreenControl"
  54. });