我如何在谷歌地图API V2我现在的位置 [英] How do I get my current location in Google Maps API V2

查看:169
本文介绍了我如何在谷歌地图API V2我现在的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个应用程序,用户需要看到getMyLocation()他/她的地理位置,但这是返回null。对此有任何解决方案,是因为我读的getMyLocation()方法总是返回null。我是新来的谷歌地图,因此任何帮助将AP preciated!

code:

  GoogleMap的地图=((SupportMapFragment)getSupportFragmentManager()findFragmentById(R.id.map)。)的GetMap()。
map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
map.setMyLocationEnabled(真正的);
位置myLocation = map.getMyLocation();

如果(myLocation!= NULL){
    helper.showToast(纬度:+ myLocation.getLatitude()+\ nLongitude:+ myLocation.getLongitude());
}
 

解决方案

请检查谷歌地图Android的API V2 的样品code,用这个你解决你的问题。

样品code

I'm creating an app where the user needs to see his/her geo location with getMyLocation(), but this is returning null. Is there any solution for this, because I did read that the getMyLocation() method is always returning null. I'm new to Google Maps, so any help will be appreciated!

Code:

GoogleMap map = ((SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
map.setMyLocationEnabled(true);
Location myLocation = map.getMyLocation();

if( myLocation != null ){
    helper.showToast( "Latitude: " + myLocation.getLatitude() + "\nLongitude: " + myLocation.getLongitude() );
}

解决方案

please check the sample code of the Google Maps Android API v2 , Using this you will solve your problem.

Sample Code

这篇关于我如何在谷歌地图API V2我现在的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆