如何获取用户附近的商户或者其他好友(LBS)

这个通常在数据库就已经把每个店的地标latitude 和longitude保存起来,然后用手机提取用户当前的location,与这些点的location比较,范围自己定。
至于比较是在服务器端做呢还是在iPhone上做呢,这个就要程序员设计,通常数据量大就在服务器做比较然后返回结果在iphone上直接显示就是了。
如果在iPhone上做比较就看我下面的代码
    CLLocation *shopLocation=[[CLLocation alloc] initWithLatitude:[[location objectForKey:@"Latitude"] doubleValue]
                longitude:[[location objectForKey:@"Longitude"] doubleValue]];
    
    CLLocation *myLocation=[[CLLocation alloc] initWithLatitude:myLocationManager.location.coordinate.latitude
                longitude:myLocationManager.location.coordinate.longitude];//在手机上测试
    
    //CLLocation *myLocation=[[CLLocation alloc] initWithLatitude:-27.44 longitude:153.00];//在simulator上测试
    
    double distance = [shopLocation getDistanceFrom:myLocation]/1000;
    NSString *distanceChange=[NSString stringWithFormat:@"%g",distance];
    NSLog(@"distance:%@ km",distanceChange);
我是把店的location放在一个Dictionary里面用来初始化shopLocation,distance = [shopLocation getDistanceFrom:myLocation]/1000这句就是用店的跟用户的比较

然后判断这个dictance是否超过你的距离,入if(dictance>5){} 


转载自:http://www.cocoachina.com/bbs/read.php?tid-70476.html



但是我发现 爱帮的API http://www.aibang.com/api/usage#locate  很是给力啊 哈哈



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值