当前位置: 编程技术>移动开发
本页文章导读:
▪上下滑动的布局 左右滑动的布局
最关键的代码:
package com.dianxing.dialog;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android..........
▪ [无线] 浅析现代 LBS 技术 [无线] 浅析当代 LBS 技术
前段时间的手机项目中涉及到目前比较火热的 LBS 概念,以下是在工作过程中积累下来的一些资料和经验,希望对一些同行有些帮助。本文将首先介绍当代 LBS 技术.........
▪ SharedPreference数据储存 SharedPreference数据存储
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//获取一个SharedPreferences对象
SharedPreferences sp .........
[1]上下滑动的布局
来源: 互联网 发布时间: 2014-02-18
左右滑动的布局
最关键的代码:
package com.dianxing.dialog;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.Scroller;
public class ScrollLayout extends ViewGroup {
private static final String TAG = "ScrollLayout";
private Scroller mScroller;
private VelocityTracker mVelocityTracker;
private int mCurScreen;
private int mDefaultScreen = 0;
private static final int TOUCH_STATE_REST = 0;
private static final int TOUCH_STATE_SCROLLING = 1;
private static final int SNAP_VELOCITY = 600;
private int mTouchState = TOUCH_STATE_REST;
private int mTouchSlop;
private float mLastMotionX;
private float mLastMotionY;
private OnCurrentViewChangedListener mOnCurrentViewChangedListener;
public OnCurrentViewChangedListener getmOnCurrentViewChangedListener() {
return mOnCurrentViewChangedListener;
}
public void setmOnCurrentViewChangedListener(
OnCurrentViewChangedListener mOnCurrentViewChangedListener) {
this.mOnCurrentViewChangedListener = mOnCurrentViewChangedListener;
}
public interface OnCurrentViewChangedListener {
public void onCurrentViewChanged(View view, int currentview);
}
public ScrollLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
// TODO 再执行这个函数
Log.i(TAG, "ScrollLayout(1)");
}
public ScrollLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO 首先执行这个函数
Log.i(TAG, "ScrollLayout(2)");
mScroller = new Scroller(context);
mCurScreen = mDefaultScreen;
mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
Log.i(TAG, "mTouchSlop ===== " + mTouchSlop);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// TODO Auto-generated method stub
Log.i(TAG, "onLayout");
Log.i(TAG, "changed === " + changed);
if (changed) {
int childLeft = 0;
final int childCount = getChildCount();
for (int i=0; i<childCount; i++) {
final View childView = getChildAt(i);
if (childView.getVisibility() != View.GONE) {
final int childWidth = childView.getMeasuredWidth();
Log.i(TAG, "childView.getMeasuredWidth() === " + childView.getMeasuredWidth());
childView.layout(childLeft, 0, childLeft+childWidth, childView.getMeasuredHeight());
Log.i(TAG, "childView.getMeasuredHeight() === " + childView.getMeasuredHeight());
childLeft += childWidth;
Log.i(TAG, "childLeft === " + childLeft);
}
}
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Log.e(TAG, "onMeasure");
Log.e(TAG, "onMeasure widthMeasureSpec === " + widthMeasureSpec);
Log.e(TAG, "onMeasure heightMeasureSpec ==== " + heightMeasureSpec);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
final int width = MeasureSpec.getSize(widthMeasureSpec);
Log.e(TAG, "width ==onMeasure== " + width);
final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
Log.e(TAG, "widthMode ==onMeasure== " + widthMode);
// if (widthMode != MeasureSpec.EXACTLY) {
// throw new IllegalStateException("ScrollLayout only canmCurScreen run at EXACTLY mode!");
// }
final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
Log.e(TAG, "heightMode ==onMeasure== " + heightMode);
// if (heightMode != MeasureSpec.EXACTLY) {
// throw new IllegalStateException("ScrollLayout only can run at EXACTLY mode!");
// }
// The children are given the same width and height as the scrollLayout
final int count = getChildCount();
Log.i(TAG, "count = getChildCount() ===== " + count);
for (int i = 0; i < count; i++) {
getChildAt(i).measure(widthMeasureSpec, heightMeasureSpec);
}
// Log.e(TAG, "moving to screen "+mCurScreen);
scrollTo(mCurScreen * width, 0);
}
/**
* According to the position of current layout
* scroll to the destination page.
*/
public void snapToDestination() {
final int screenWidth = getWidth();
Log.i(TAG, "screenWidth ==snapToDestination== " + screenWidth);
final int destScreen = (getScrollX()+ screenWidth/2)/screenWidth;
Log.i(TAG, "destScreen ==snapToDestination== " + destScreen);
snapToScreen(destScreen);
}
public void snapToScreen(int whichScreen) {
// get the valid layout page
whichScreen = Math.max(0, Math.min(whichScreen, getChildCount()-1));
Log.i(TAG, "whichScreen ==== " + whichScreen);
Log.i(TAG, "getScrollX() ==== " + getScrollX());
Log.i(TAG, "whichScreen*getWidth() ==== " + whichScreen*getWidth());
if (getScrollX() != (whichScreen*getWidth())) {
final int delta = whichScreen*getWidth()-getScrollX();
Log.i(TAG, "delta ===== " + delta);
mScroller.startScroll(getScrollX(), 0, delta, 0, Math.abs(delta)*2);
mCurScreen = whichScreen;
Log.i(TAG, "mCurScreen = whichScreen ===== " + mCurScreen );
// 这里监听是为了在滑动的时候能改变的button的图�?
if (mOnCurrentViewChangedListener != null) {
mOnCurrentViewChangedListener.onCurrentViewChanged(this,mCurScreen);
}
invalidate(); // Redraw the layout
}
}
public void setToScreen(int whichScreen) {
Log.i(TAG, "whichScreen ==setToScreen== " + whichScreen);
whichScreen = Math.max(0, Math.min(whichScreen, getChildCount()-1));
mCurScreen = whichScreen;
scrollTo(whichScreen*getWidth(), 0);
// TODO 在这里做监听主要是为了点击button的时候,能够把当前的mCurScreen传给mOnCurrentViewChangedListener,使得达到改变图片的状
if (mOnCurrentViewChangedListener != null) {
mOnCurrentViewChangedListener.onCurrentViewChanged(this,mCurScreen);
}
}
public int getCurScreen() {
return mCurScreen;
}
@Override
public void computeScroll() {
// TODO Auto-generated method stub
Log.i(TAG, "computeScroll()");
if (mScroller.computeScrollOffset()) {
scrollTo(mScroller.getCurrX(), mScroller.getCurrY());
postInvalidate();
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
}
mVelocityTracker.addMovement(event);
final int action = event.getAction();
final float x = event.getX();
final float y = event.getY();
switch (action) {
case MotionEvent.ACTION_DOWN:
Log.e(TAG, "event down!");
if (!mScroller.isFinished()){
mScroller.abortAnimation();
}
mLastMotionX = x;
break;
case MotionEvent.ACTION_MOVE:
int deltaX = (int)(mLastMotionX - x);
mLastMotionX = x;
Log.v(TAG, "event ACTION_MOVE");
scrollBy(deltaX, 0);
break;
case MotionEvent.ACTION_UP:
Log.e(TAG, "event : up");
// if (mTouchState == TOUCH_STATE_SCROLLING) {
final VelocityTracker velocityTracker = mVelocityTracker;
velocityTracker.computeCurrentVelocity(1000);
int velocityX = (int) velocityTracker.getXVelocity(); // 滑动的速度,左边为负,右边为正
Log.e(TAG, "velocityX:"+velocityX);
if (velocityX > SNAP_VELOCITY && mCurScreen > 0) {
// Fling enough to move left
Log.e(TAG, "snap 向右滑动");
snapToScreen(mCurScreen - 1);
} else if (velocityX < -SNAP_VELOCITY && mCurScreen < getChildCount() - 1) {
// Fling enough to move right,
Log.e(TAG, "snap 向左滑动");
snapToScreen(mCurScreen + 1);
} else {
snapToDestination();
}
if (mVelocityTracker != null) {
mVelocityTracker.recycle();
mVelocityTracker = null;
}
// }
mTouchState = TOUCH_STATE_REST;
break;
case MotionEvent.ACTION_CANCEL:
mTouchState = TOUCH_STATE_REST;
break;
}
return true;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
// TODO Auto-generated method stub
Log.e(TAG, "onInterceptTouchEvent-slop:"+mTouchSlop);
final int action = ev.getAction();
Log.i(TAG, "action ==== " + action);
if ((action == MotionEvent.ACTION_MOVE) && (mTouchState != TOUCH_STATE_REST)) {
return true;
}
final float x = ev.getX();
final float y = ev.getY();
switch (action) {
case MotionEvent.ACTION_MOVE:
final int xDiff = (int)Math.abs(mLastMotionX-x);
if (xDiff>mTouchSlop) {
Log.i(TAG, "MotionEvent.ACTION_MOVE");
mTouchState = TOUCH_STATE_SCROLLING;
}
break;
case MotionEvent.ACTION_DOWN:
Log.v(TAG, "MotionEvent.ACTION_DOWN");
mLastMotionX = x;
mLastMotionY = y;
mTouchState = mScroller.isFinished()? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING;
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
Log.e(TAG, "MotionEvent.ACTION_UP");
mTouchState = TOUCH_STATE_REST;
break;
}
return mTouchState != TOUCH_STATE_REST;
}
}
主页面:
package com.dianxing.dialog;
import com.dianxing.dialog.ScrollLayout.OnCurrentViewChangedListener;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MeMainActivity extends Activity {
private LinearLayout layout;
private ScrollLayout scrollLayout;
private ImageButton imageButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
layout = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.memain, null);
scrollLayout = (ScrollLayout) layout.findViewById(R.id.scroll_privage);
scrollLayout.setmOnCurrentViewChangedListener(mOnCurrentViewChangedListener);
getLayout();
setContentView(layout);
}
private void getLayout(){
// TODO 添加布局页面
final LayoutInflater layoutInflater = LayoutInflater.from(getApplicationContext());
for(int i=0; i < 10 ; i++){
Log.i("Main", i + "");
final View view = layoutInflater.inflate(R.layout.meitem, null);
final LinearLayout item_fisrtLayout = (LinearLayout) view.findViewById(R.id.item_fisrtLayout);
TextView textView = (TextView) view.findViewById(R.id.tv);
ImageView iamgeViewLeft = (ImageView) view.findViewById(R.id.iamgeViewLeft);
ImageView iamgeViewRight = (ImageView) view.findViewById(R.id.iamgeViewRight);
iamgeViewLeft.setImageDrawable(getResources().getDrawable(R.drawable.qwe));
iamgeViewRight.setImageDrawable(getResources().getDrawable(R.drawable.awq));
scrollLayout.addView(item_fisrtLayout);
// TODO 添加按钮
final LinearLayout imageButtonLayout = (LinearLayout) layout.findViewById(R.id.imageButtonLayout);
final View viewButton = layoutInflater.inflate(R.layout.mebutton, null);
imageButton = (ImageButton) viewButton.findViewById(R.id.imageButton);
imageButtonLayout.addView(imageButton);
}
}
private OnCurrentViewChangedListener mOnCurrentViewChangedListener = new OnCurrentViewChangedListener() {
@Override
public void onCurrentViewChanged(View view, int currentview) {
Log.i("Main", "currentview ==== " + currentview );
if(currentview == 0){
imageButton.setImageDrawable(getResources().getDrawable(R.drawable.mv_dot_light));
}
}
};
}
memain.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="fill_parent">
<TextView
android:id="@+id/title_tv"
android:text="北京*东直门"
android:layout_marginTop="5dip"
android:gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:background="#999999"
android:orientation="vertical"
android:layout_marginTop="5dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<com.dianxing.dialog.ScrollLayout
android:id="@+id/scroll_privage"
android:layout_width="fill_parent"
android:layout_height="130dip">
</com.dianxing.dialog.ScrollLayout>
<LinearLayout
android:id="@+id/imageButtonLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginBottom="5dip"
android:orientation="horizontal">
</LinearLayout>
</LinearLayout>
</LinearLayout>
meitem.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/item_fisrtLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv"
android:layout_marginLeft="20dip"
android:textSize="20sp"
android:paddingTop="5dip"
android:layout_width="wrap_content"
android:layout_height="30dip"
android:singleLine="true"
android:text="你可能喜欢的优惠.你可能喜欢的优惠。。。。"
android:ellipsize="end"
android:textColor="#F0F0"/>
<LinearLayout
android:orientation="horizontal"
android:gravity="center_horizontal"
android:paddingTop="5dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/iamgeViewLeft"
android:layout_marginRight="5dip"
android:layout_width="135dip"
android:background="@drawable/qwe"
android:layout_height="90dip"
android:textColor="#F0F0"/>
<ImageView
android:id="@+id/iamgeViewRight"
android:layout_marginLeft="5dip"
android:layout_width="130dip"
android:layout_height="90dip"
android:background="@drawable/awq"
android:textColor="#F0F0"/>
</LinearLayout>
</LinearLayout>
mebutton.xml:
<?xml version="1.0" encoding="utf-8"?>
<ImageButton
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:background="#00000000"
android:layout_height="wrap_content"
android:padding="3dip"
android:src="/blog_article/@drawable/mv_dot_light/index.html"/>
1 楼
573842281
2012-05-11
写得不错,如果配个图就更好了!
2 楼
夏文权
2012-05-28
呵呵, 会尽量配好,最近还没有时间。
[2] [无线] 浅析现代 LBS 技术
来源: 互联网 发布时间: 2014-02-18
[无线] 浅析当代 LBS 技术
前段时间的手机项目中涉及到目前比较火热的 LBS 概念,以下是在工作过程中积累下来的一些资料和经验,希望对一些同行有些帮助。本文将首先介绍当代 LBS 技术的商业模式以及技术关键点,进而再分析一下目前改技术存在的缺陷和挑战,最后是总结和展望。
1> 技术简介和商业模式
基于位置的服务(Location Based Service,LBS),它是通过电信移动运营商的无线电通讯网络(如GSM网、CDMA网)或外部定位方式(如GPS)获取移动终端用户的位置信息(地理坐标,或大地坐标),在GIS(Geographic Information System,地理信息系统)平台的支持下,为用户提供相应服务的一种增值业务。
目前LBS技术在商业中的应用主要有四类:
1、 切客(Check-In)模式:主要是以Foursquare为主,还有一些国外同类服务还有Gowalla、Whrrl等,而国内则有:切客、四方、街旁、开开、多乐趣、在哪儿等。该模式的最大挑战在于要培养用户每到一个地点就会签到(Check-In)的习惯。而它的商业模式也是比较明显,可以很好地为商户或品牌进行各种形式的营 销与推广。而国内比较活跃的街旁网现阶段则更多地与各种音乐会、展览等文艺活动合作,慢慢向年轻人群推广与渗透,积累用户。
2、 游戏模式:国外的代表是MyTown,国内则是16Fun。主旨是游戏人生,可以让用户利用手机购买现实地理位置里的虚拟房产与道具,并进行消费与互动等将现实和虚拟真正进行融合的一种模式。这种模式的特点是更具趣味性,可玩性与互动性更强,比Check-In模式更具粘性,但是由于需要对现实中的房产等地点进行虚拟化设计,开发成本较高,并且由于地域性过强导致覆盖速度不可能很快。在商业模式方面,除了借鉴Check-In模式的联合商家营销外,还可提供增值服务,以及类似第二人生(Second-Life)的植入广告等。
3、 生活服务型:以点评网或者生活信息类网站与地理位置服务结合的模式,代表大众点评网、台湾的“折扣王”等。主要体验在于工具性的实用特质,问题在于信息量的积累和覆盖面需要比较广泛。除此之外,LBS也渐渐渗透到旅游、票务、信用卡等日常生活服务的方方面面,使我们的生活更加便利与时尚。
4、 电子商务型:在这个领域,美国的GroupTabs给我们带来了新的想象,GroupTabs的用户到一些本地的签约商家,比如一间酒吧,到达后使用GroupTabs的手机应用进行Check-In。当Check-In的数量到达一定数量后,所有进行过Check-In的用户就可以得到一定的折扣或优惠。另外,也有一些服务商利用LBS进行优惠信息推送,与商户、用户一起获得“三赢”的好处。
2> 如何定位坐标
目前不管是Android还是IPhone,都有系统原生的API来获取用户当前的位置坐标信息。而定位方式一般分为:GPS定位、基站定位两种。这两种定位方式各有长短:
1、 GPS定位:优点是比较精确,根据我们内部的测试数据,平均精度在10米左右,另外还包含高度信息;而缺点则是信息返回比较慢,定位时间往往在几十秒到几分钟不等。
2、 基站定位:优点是返回速度快,一般是秒级别的,但是问题是定位不够精确,据我们内部的测试数据,平均精度在500米左右。
另外,对于Android和IPhone系统来说对于定位的算法也有区别:
1、 对于Android来说:可以使用API分别计算出GPS位置和基站定位位置,也可以自己编程实现最优算法,比较灵活;基于节省带宽和为用户省电的出发点考虑,我们在定位算法的设计上,我们首先应该制定一个比较合理的精度值,然后结合返回时间的长短,实现一套最优的算法。
2、 对于Iphone来说:可以根据自定义的精度来返回最佳的定位信息,当然越精确的数据返回的时间就会越长,我们可以根据具体的需求来制定一个比较合理的精度值。
此外,由于Iphone4之后的机型都自带陀螺仪,因此只要用户之前上过一段时间的GPS,就算之后没有GPS信号了,也可以根据陀螺仪提供的运动轨迹模拟计算出用户目前的所在位置,据测试这个值还是很准的,而Android的机型比较多,据说在2.3之后的机型里面也会慢慢的配上陀螺仪,但是基于兼容性考虑,我们还是要多考虑老款的机型。
3> 结合地图应用
目前有几个比较好的选择,都可通过SDK嵌入到程序中去:
1、 Google地图API:http://code.google.com/intl/zh-CN/apis/maps/
2、 Mapbar地图API:http://open.mapbar.com/
3、 Mapabc地图API:http://code.mapabc.com/
以上地图服务的功能甚至API调用都非常类似,对目前我们需要的功能列举说明如下:
1、 地图移动以及缩放功能:都有。
2、 根据经纬度定位功能:都有。
3、 添加/显示标注功能:都有。
4、 POI查询功能:只有Mapbac提供。
5、 精确地理位置信息:只有Mapabc提供。
总结如下:其中前者可以作为国际地图服务的选择,而后两者比较适合国内服务。Mapbar的界面比较美观点,但是功能有限(很多功能需要基于商务合作),而且暂时没有iOS版的;Mapabc界面普通点,但是免费功能比较多,不但提供精确位置查询,还有免费的POI查询接口(虽然数据比较旧),如果需要最新的数据估计也需要通过商务合作的方式。
4> 当代技术的缺陷和挑战
任何一种先进的技术,都不会是完美的。如果等到技术完美了再去做应用的话,那么这个应用的市场早就被别人占领了。应用和技术之间的关系在于,到底是新技术产生推动新的应用模式,还是新的应用模式需要更新的技术。下面我们来了解一下现在LBS技术的一些主要问题并探讨一下比较可行的。这对我们在这个领域的研究工作还是有很大意义的。
4.1、精确定位问题
既然是LBS,那么定位肯定是越精确越好。单从GPS技术来看,其本身的精度还是很高的,但是我们现在使用的是美国的GPS民用信号,这种技术的最高精度,也就是十几米。这种误差分为两个方面,第一是美国人故意放进去的,是一个偏移量。而在GPS技术最早引入国内的时候,当时的工程师其实是想到了一些提高精确度的办法的:那就是在城市中最高的地标建筑物上,通常是电视塔里面,安装一个校正信号发射器。遗憾的是,后来这个方案没有得意实施,主要是为了国家安全方面的考虑(无解了)。目前网络上能找到一些偏移量的纠正算法,不过是否准确合适还有待检验。
好在就我们目前内部的测试结果来看,GPS定位的平均精度在10米左右,应该说已经是相当精确了,而对于我们目前的Gamelive项目来说,如此的精度也基本上足够了,因为我们主要需要获取的是用户周围区域内的玩家,可以允许有一定的误差在里面。
另外,按照我们内部的测试,经纬度变化0.0009相差100米,目前Map API的一般精度在E6,也就是0.11米。
4.2、室内定位问题
现代都市人,大部分生活都是在室内的。但是GPS信号在室内是收不到的。那么在室内,特别是一栋巨大的商场内部如何定位呢,这就成了一个严重的问题。而恰巧目前那些基于信息点的服务,那些信息点大多是一些商铺、餐厅。这些机构实际上是信息点服务的现金支付者,如果他们吸引不到用户,那么他们就不会向LBS服务商支付费用,最终就会导致这种服务体系的崩溃。大部分LBS应用只能知道,现在用户在这座大楼里面,但是具体在什么位置,就不得而知了。
现在部分比较新的手机厂商通过陀螺仪来解决这个问题,这确实是一个不错的。实际上现代陀螺仪已经是现代航空,航海,航天和国防工业中广泛使用的一种惯性导航仪器,它可以根据需要,提供准确的方位、水平、位置、速度和加速度等信号,而且定位非常精确,确实是LBS技术一个良好的补充。
据了解目前Iphone4上已经配备了陀螺仪,而Android2.3以上的部分设备上也有配备,而系统给我们返回的定位信息已经自动矫正优化过的了,所以相信以后的LBS室内定位应该不会有什么大问题。但是就目前阶段,我们还须考虑到不同设备的问题。
4.3、设备耗电量问题
定位服务耗电这是众所周知的事情了,所以我们一定要设置一个比较合理的周期来做这个事情,目前1-5分钟定位一次是比较合理的范围。
5> 总结和展望
通过我们团队的分析,目前可以预见的是,随着无线终端日渐强大,LBS 技术也将会日渐成熟,进而深入到人们日常生活中去。来自艾媒市场咨询的数据显示:2010年中国位置服务行业市场规模有望达到9.98亿人民币,预计到2013年,中国LBS个人“切客”应用市场总体规模将近百亿。而尽早掌握这个领域的技术和资源是我们目前工作的重中之重。
前段时间的手机项目中涉及到目前比较火热的 LBS 概念,以下是在工作过程中积累下来的一些资料和经验,希望对一些同行有些帮助。本文将首先介绍当代 LBS 技术的商业模式以及技术关键点,进而再分析一下目前改技术存在的缺陷和挑战,最后是总结和展望。
1> 技术简介和商业模式
基于位置的服务(Location Based Service,LBS),它是通过电信移动运营商的无线电通讯网络(如GSM网、CDMA网)或外部定位方式(如GPS)获取移动终端用户的位置信息(地理坐标,或大地坐标),在GIS(Geographic Information System,地理信息系统)平台的支持下,为用户提供相应服务的一种增值业务。
目前LBS技术在商业中的应用主要有四类:
1、 切客(Check-In)模式:主要是以Foursquare为主,还有一些国外同类服务还有Gowalla、Whrrl等,而国内则有:切客、四方、街旁、开开、多乐趣、在哪儿等。该模式的最大挑战在于要培养用户每到一个地点就会签到(Check-In)的习惯。而它的商业模式也是比较明显,可以很好地为商户或品牌进行各种形式的营 销与推广。而国内比较活跃的街旁网现阶段则更多地与各种音乐会、展览等文艺活动合作,慢慢向年轻人群推广与渗透,积累用户。
2、 游戏模式:国外的代表是MyTown,国内则是16Fun。主旨是游戏人生,可以让用户利用手机购买现实地理位置里的虚拟房产与道具,并进行消费与互动等将现实和虚拟真正进行融合的一种模式。这种模式的特点是更具趣味性,可玩性与互动性更强,比Check-In模式更具粘性,但是由于需要对现实中的房产等地点进行虚拟化设计,开发成本较高,并且由于地域性过强导致覆盖速度不可能很快。在商业模式方面,除了借鉴Check-In模式的联合商家营销外,还可提供增值服务,以及类似第二人生(Second-Life)的植入广告等。
3、 生活服务型:以点评网或者生活信息类网站与地理位置服务结合的模式,代表大众点评网、台湾的“折扣王”等。主要体验在于工具性的实用特质,问题在于信息量的积累和覆盖面需要比较广泛。除此之外,LBS也渐渐渗透到旅游、票务、信用卡等日常生活服务的方方面面,使我们的生活更加便利与时尚。
4、 电子商务型:在这个领域,美国的GroupTabs给我们带来了新的想象,GroupTabs的用户到一些本地的签约商家,比如一间酒吧,到达后使用GroupTabs的手机应用进行Check-In。当Check-In的数量到达一定数量后,所有进行过Check-In的用户就可以得到一定的折扣或优惠。另外,也有一些服务商利用LBS进行优惠信息推送,与商户、用户一起获得“三赢”的好处。
2> 如何定位坐标
目前不管是Android还是IPhone,都有系统原生的API来获取用户当前的位置坐标信息。而定位方式一般分为:GPS定位、基站定位两种。这两种定位方式各有长短:
1、 GPS定位:优点是比较精确,根据我们内部的测试数据,平均精度在10米左右,另外还包含高度信息;而缺点则是信息返回比较慢,定位时间往往在几十秒到几分钟不等。
2、 基站定位:优点是返回速度快,一般是秒级别的,但是问题是定位不够精确,据我们内部的测试数据,平均精度在500米左右。
另外,对于Android和IPhone系统来说对于定位的算法也有区别:
1、 对于Android来说:可以使用API分别计算出GPS位置和基站定位位置,也可以自己编程实现最优算法,比较灵活;基于节省带宽和为用户省电的出发点考虑,我们在定位算法的设计上,我们首先应该制定一个比较合理的精度值,然后结合返回时间的长短,实现一套最优的算法。
2、 对于Iphone来说:可以根据自定义的精度来返回最佳的定位信息,当然越精确的数据返回的时间就会越长,我们可以根据具体的需求来制定一个比较合理的精度值。
此外,由于Iphone4之后的机型都自带陀螺仪,因此只要用户之前上过一段时间的GPS,就算之后没有GPS信号了,也可以根据陀螺仪提供的运动轨迹模拟计算出用户目前的所在位置,据测试这个值还是很准的,而Android的机型比较多,据说在2.3之后的机型里面也会慢慢的配上陀螺仪,但是基于兼容性考虑,我们还是要多考虑老款的机型。
3> 结合地图应用
目前有几个比较好的选择,都可通过SDK嵌入到程序中去:
1、 Google地图API:http://code.google.com/intl/zh-CN/apis/maps/
2、 Mapbar地图API:http://open.mapbar.com/
3、 Mapabc地图API:http://code.mapabc.com/
以上地图服务的功能甚至API调用都非常类似,对目前我们需要的功能列举说明如下:
1、 地图移动以及缩放功能:都有。
2、 根据经纬度定位功能:都有。
3、 添加/显示标注功能:都有。
4、 POI查询功能:只有Mapbac提供。
5、 精确地理位置信息:只有Mapabc提供。
总结如下:其中前者可以作为国际地图服务的选择,而后两者比较适合国内服务。Mapbar的界面比较美观点,但是功能有限(很多功能需要基于商务合作),而且暂时没有iOS版的;Mapabc界面普通点,但是免费功能比较多,不但提供精确位置查询,还有免费的POI查询接口(虽然数据比较旧),如果需要最新的数据估计也需要通过商务合作的方式。
4> 当代技术的缺陷和挑战
任何一种先进的技术,都不会是完美的。如果等到技术完美了再去做应用的话,那么这个应用的市场早就被别人占领了。应用和技术之间的关系在于,到底是新技术产生推动新的应用模式,还是新的应用模式需要更新的技术。下面我们来了解一下现在LBS技术的一些主要问题并探讨一下比较可行的。这对我们在这个领域的研究工作还是有很大意义的。
4.1、精确定位问题
既然是LBS,那么定位肯定是越精确越好。单从GPS技术来看,其本身的精度还是很高的,但是我们现在使用的是美国的GPS民用信号,这种技术的最高精度,也就是十几米。这种误差分为两个方面,第一是美国人故意放进去的,是一个偏移量。而在GPS技术最早引入国内的时候,当时的工程师其实是想到了一些提高精确度的办法的:那就是在城市中最高的地标建筑物上,通常是电视塔里面,安装一个校正信号发射器。遗憾的是,后来这个方案没有得意实施,主要是为了国家安全方面的考虑(无解了)。目前网络上能找到一些偏移量的纠正算法,不过是否准确合适还有待检验。
好在就我们目前内部的测试结果来看,GPS定位的平均精度在10米左右,应该说已经是相当精确了,而对于我们目前的Gamelive项目来说,如此的精度也基本上足够了,因为我们主要需要获取的是用户周围区域内的玩家,可以允许有一定的误差在里面。
另外,按照我们内部的测试,经纬度变化0.0009相差100米,目前Map API的一般精度在E6,也就是0.11米。
4.2、室内定位问题
现代都市人,大部分生活都是在室内的。但是GPS信号在室内是收不到的。那么在室内,特别是一栋巨大的商场内部如何定位呢,这就成了一个严重的问题。而恰巧目前那些基于信息点的服务,那些信息点大多是一些商铺、餐厅。这些机构实际上是信息点服务的现金支付者,如果他们吸引不到用户,那么他们就不会向LBS服务商支付费用,最终就会导致这种服务体系的崩溃。大部分LBS应用只能知道,现在用户在这座大楼里面,但是具体在什么位置,就不得而知了。
现在部分比较新的手机厂商通过陀螺仪来解决这个问题,这确实是一个不错的。实际上现代陀螺仪已经是现代航空,航海,航天和国防工业中广泛使用的一种惯性导航仪器,它可以根据需要,提供准确的方位、水平、位置、速度和加速度等信号,而且定位非常精确,确实是LBS技术一个良好的补充。
据了解目前Iphone4上已经配备了陀螺仪,而Android2.3以上的部分设备上也有配备,而系统给我们返回的定位信息已经自动矫正优化过的了,所以相信以后的LBS室内定位应该不会有什么大问题。但是就目前阶段,我们还须考虑到不同设备的问题。
4.3、设备耗电量问题
定位服务耗电这是众所周知的事情了,所以我们一定要设置一个比较合理的周期来做这个事情,目前1-5分钟定位一次是比较合理的范围。
5> 总结和展望
通过我们团队的分析,目前可以预见的是,随着无线终端日渐强大,LBS 技术也将会日渐成熟,进而深入到人们日常生活中去。来自艾媒市场咨询的数据显示:2010年中国位置服务行业市场规模有望达到9.98亿人民币,预计到2013年,中国LBS个人“切客”应用市场总体规模将近百亿。而尽早掌握这个领域的技术和资源是我们目前工作的重中之重。
[3] SharedPreference数据储存
来源: 互联网 发布时间: 2014-02-18
SharedPreference数据存储
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//获取一个SharedPreferences对象
SharedPreferences sp = getSharedPreferences("dataInfo", 0);
String user = sp.getString("user", "");
String password = sp.getString("password", "");
((EditText)findViewById(R.id.user)).setText(user);
((EditText)findViewById(R.id.password)).setText(password);
}
@Override
protected void onStop() {
super.onStop();
SharedPreferences sp = getSharedPreferences("dataInfo", 0);
sp.edit().putString("user",
((EditText)findViewById(R.id.user)).getText().toString())
.putString("password",
((EditText)findViewById(R.id.password)).getText().toString())
.commit();
}
最新技术文章: