def transCoordinates(self, latitudes, longitudes, fromtype=COORDTYPE, totype=COORDTYPE): '''批量转换坐标系''' lats = splitstrip(latitudes, ',') lngs = splitstrip(longitudes, ',') if len(lats) != len(lngs): raise ex(u'长度不相等') cs = [] for lat, lng in zip(lats, lng): r = self.transCoordinateOne(lat, lng, fromtype, totype) cs.append({ 'longitude': r[0], 'latitude': r[1], }) return {'coordtype': totype, 'items': cs}
def getAddressByLatLng(self, latitude, longitude, coordtype): res = self.getAddressResByLatLng(latitude, longitude, coordtype) try: from preset.models import Area adcode = res['result']['addressComponent']['adcode'] data = res['result']['addressComponent'] areanames = filter( lambda x: x, [data['province'], data['city'], data['district']]) area = adcode and Area.objects.filter( code=adcode).first() or Area.getAreaByNames( u' '.join(areanames)) or None return { 'coordtype': coordtype, 'latitude': latitude, 'longitude': longitude, 'areanames': area and area.names, 'address': res['result']['sematic_description'], } except Exception, e: print e raise ex(e.message)
def transCoordinateOne(self, latitude, longitude, fromtype=COORDTYPE, totype=COORDTYPE): from base import gpsutils longitude = float(longitude) latitude = float(latitude) r = None if fromtype == totype: r = [longitude, latitude] elif fromtype == 'wgs84' and totype == 'bd09ll': r = gpsutils.wgs84togcj02(longitude, latitude) r = gpsutils.gcj02tobd09(r[0], r[1]) elif fromtype == 'wgs84' and totype == 'gcj02': r = gpsutils.wgs84togcj02(longitude, latitude) elif fromtype == 'gcj02' and totype == 'wgs84': r = gpsutils.gcj02towgs84(longitude, latitude) elif fromtype == 'bd09ll' and totype == 'wgs84': r = gpsutils.bd09togcj02(longitude, latitude) r = gpsutils.gcj02towgs84(r[0], r[1]) else: raise ex(u'未支持的类型:%s->%s' % (fromtype, totype)) return r
def verify_phone(self, phone): from base.utils import isphone if not isphone(phone): raise ex(u'手机格式不对')
def verify_objuser(self, obj): if hasattr(obj, 'user_id'): uid = getattr(obj, 'user_id') if uid != self.get_meid(): raise ex(u'访问受限') return True
def getModel(self, modelname): model = self.get_model(modelname) if not model: raise ex(u'不存在模型:%s' % modelname) return model