Titanium 获取当前地理位置(经纬度)Get the current location (latitude and longitude)
2017-03-27 17:39
751 查看
coffee 代码,下边的例子是用作实现签到功能的(需要js格式请去http://js2.coffee 上转换)
附带一个android bug
解决办法是 使 用 android 真 机 调 试!
ios 也需要真机。
#================= 获取android 地理位置 ================== get_current_position_for_android = -> Ti.Geolocation.Android.manualMode = true network_provider = Ti.Geolocation.Android.createLocationProvider name: Ti.Geolocation.PROVIDER_NETWORK, minUpdateDistance: 0.0, minUpdateTime: 1 Ti.Geolocation.Android.addLocationProvider network_provider gps_provider = Ti.Geolocation.Android.createLocationProvider name: Ti.Geolocation.PROVIDER_GPS, minUpdateDistance: 0.0, minUpdateTime: 1 Ti.Geolocation.Android.addLocationProvider gps_provider gps_rule = Ti.Geolocation.Android.createLocationRule provider: Ti.Geolocation.PROVIDER_GPS, maxAge: 3000, accuracy: 100, minAge: 1000 Ti.Geolocation.Android.addLocationRule gps_rule net_rule = Ti.Geolocation.Android.createLocationRule provider: Ti.Geolocation.PROVIDER_NETWORK, maxAge: 3000, accuracy: 100, minAge: 1000 Ti.Geolocation.Android.addLocationRule net_rule #Ti.Geolocation.Android.manualMode = true location_callback = (e) -> if !e.success ||e.error show_alert "提示","签到失败,请重试!" return Ti.Geolocation.removeEventListener 'location',location_callback longitude = e.coords.longitude latitude = e.coords.latitude distance = getDistance(latitude, longitude, decorating_case_latitude, decorating_case_longitude) if distance < 1 show_notice '距离超过1000米,不能签到' return post_longitude_and_latitude(longitude,latitude) Ti.Geolocation.addEventListener 'location',location_callback provider_network = null provider_gps = null #================= 获取ios 地理位置 ================== get_current_position_for_ios = -> Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST Titanium.Geolocation.getCurrentPosition (e) -> if (!e.success || e.error) show_alert("提示",'error ' + JSON.stringify(e.error)) longitude = e.coords.longitude latitude = e.coords.latitude altitude = e.coords.altitude heading = e.coords.heading accuracy = e.coords.accuracy speed = e.coords.speed timestamp = e.coords.timestamp altitudeAccuracy = e.coords.altitudeAccuracy distance = getDistance(latitude, longitude, decorating_case_latitude, decorating_case_longitude) if distance > 1 show_notice '距离超过1000米,不能签到' return post_longitude_and_latitude(longitude,latitude)
附带一个android bug
解决办法是 使 用 android 真 机 调 试!
ios 也需要真机。
相关文章推荐
- Android 成功 使用GPS获取当前地理位置(解决getLastKnownLocation 返回 null)
- Android 成功 使用GPS获取当前地理位置(解决getLastKnownLocation 返回 null)
- Android 成功 使用GPS获取当前地理位置(解决getLastKnownLocation 返回 null)
- Android 成功 使用GPS获取当前地理位置(解决getLastKnownLocation 返回 null)
- Android 成功 使用GPS获取当前地理位置(解决getLastKnownLocation)
- Android 成功 使用GPS获取当前地理位置(解决getLastKnownLocation 返回 null)
- Latitude, Longitude, PHP and the Yahoo Geocoder PHP 通过 Yahoo Geocoder 获得地理经纬度
- Android 成功 使用GPS获取当前地理位置(解决getLastKnownLocation 返回 null)
- Android 成功 使用GPS获取当前地理位置(解决getLastKnownLocation 返回 null)
- 微信小程序 获取当前地理位置和经纬度实例代码
- [android] 百度地图开发 (三).定位当前位置及getLastKnownLocation获取location总为空问题
- html5获取用户当前的地理位置,即经纬度。
- js获取当前位置的地理坐标(经纬度)
- android getLastKnownLocation()获取当前位置为null解决方法
- android:GPS获取location经纬度并用谷歌解析为地理位置名称
- 用js获取当前地理位置的经纬度
- WinAPI: GetCurrentPositionEx - 获取当前的画笔位置
- android 中获取当前焦点所在屏幕中的位置 view.getLocationOnScreen(location)
- 源码推荐(1.12):ZYDrawString实现对字符串的画线动画,iOS8获取当前经纬度、地理位置
- 用Android Location获取当前地理位置的方法