2011-04-17 70 views
0

新的Android开发,并试图创建地图应用程序的功能。Android的GPS和位置服务帮助

1)发射的MapView 2)显示表示所述用户的当前位置 3)中显示图标的代表当地的地标(例如一个图标:健身房,餐厅) 4)当用户敲击任何给定的地标图标的弹出显示名称,地址和选项来启动GPS(按转向)方向。

这可以在android中完成吗?我是否必须以编程方式输入lat & lon?

回答

1

是的。这可以在android中完成。您可以通过您的gps或网络(wi-fi或蜂窝网络)找到位置。但通常gps非常耗时,因此您将gps和网络来确定你的位置。这个链接会给你一个更好的想法如何获得用户位置http://developer.android.com/guide/topics/location/obtaining-user-location.html

这是检索位置的示例代码。请记住按照上述链接并请求位置更新。

LocationManager locationManager= (LocationManager) getSystemService(context); 
     Criteria criteria = new Criteria(); 
      criteria.setAccuracy(Criteria.ACCURACY_FINE); 
      criteria.setAltitudeRequired(false); 
      criteria.setBearingRequired(false); 
      criteria.setCostAllowed(true); 
      criteria.setPowerRequirement(Criteria.POWER_LOW); 
      provider = locationManager.getBestProvider(criteria, true); 
    Location location = locationManager.getLastKnownLocation(provider) 

在这里,在上面的代码中你的经度和纬度将被存储在变量location.Remember里面添加位置监听器和请求位置更新。

+0

嗨,感谢您的回复。所以如果上面的代码找到了用户当前的位置,怎么会在mapview上显示本地健身房呢?有没有提供教程的书? – user590690 2011-04-17 19:51:34

+0

如果你问我一本书,我会建议Reto Me的“Professional android development 2”。 – rogerstone 2011-04-18 01:38:02

+0

看到这篇文章。这会让你开始在地图上显示感兴趣的地方.http://stackoverflow.com/questions/2631742/given-gps-coordinates-how-do-i-find-nearby-landmarks-or -兴趣点。 至于一本书,我肯定会推荐“专业Android 2应用程序开发” - Reto Meier.It可能没有教程解释你想要什么,但它有很多例子,你可以在 – rogerstone 2011-04-18 01:45:05