Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 地理定位谷歌地图v2_Java_Android_Google Maps - Fatal编程技术网

Java 地理定位谷歌地图v2

Java 地理定位谷歌地图v2,java,android,google-maps,Java,Android,Google Maps,我正在使用谷歌地图V2获取我的当前位置和行程 我的手机连接到互联网和GPS工作,但结果令人失望 有时我会说:“不可用”,同时它会告诉我连接的laaast点的位置,而不是电流 这是我的密码 public class ItineraryActivity extends Activity { private static final LatLng Event_place = new LatLng(33.59648, -7.664723); private static final LatLng MO

我正在使用谷歌地图V2获取我的当前位置和行程 我的手机连接到互联网和GPS工作,但结果令人失望 有时我会说:“不可用”,同时它会告诉我连接的laaast点的位置,而不是电流 这是我的密码

public class ItineraryActivity extends Activity {

private static final LatLng Event_place = new LatLng(33.59648, -7.664723);
private static final LatLng MOUNTAIN_VIEW = new LatLng(37.4, -122.1);
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
private GoogleMap map;
private LocationManager service;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mapevent);
    findViewById(R.id.direction).setVisibility(View.INVISIBLE);
    map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
            .getMap();
    map.setMapType(GoogleMap.MAP_TYPE_NORMAL);

    Marker hamburg = map.addMarker(new MarkerOptions()
            .position(Event_place).title("Our event")
            .snippet("We are waiting for you .."));

    map.moveCamera(CameraUpdateFactory.newLatLngZoom(Event_place, 15));
    /** Geo */
    service = (LocationManager) getSystemService(LOCATION_SERVICE);
    boolean enabled = service
            .isProviderEnabled(LocationManager.GPS_PROVIDER);
    // Activer GPS
    if (!enabled) {
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        startActivity(intent);
        Log.e("eeee", "law 3lem");

    } else {
        Log.e("eeee", "law ");
    }
    // **
    Criteria criteria = new Criteria();
    String provider = service.getBestProvider(criteria, false);
    Location location = service.getLastKnownLocation(provider);
    // Initialize the location fields
    if (location != null) {
        System.out.println("Provider " + provider + " has been selected.");
        onLocationChanged(location);
        new Routing(this, map, Color.BLACK).execute(
                new LatLng(location.getLatitude(), location.getLongitude()),
                Event_place);

    } else {
        Log.e("", "not available");
    }


}

public void onLocationChanged(Location location) {
    double lat = (double) (location.getLatitude());
    double lng = (double) (location.getLongitude());

    Log.e("lat + long", String.valueOf(lat) + " / " + String.valueOf(lng));

    map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng),
            14));
    map.addMarker(new MarkerOptions()
            .position(new LatLng(lat, lng))
            .title("Vous êtes là")
            .snippet("Nous comptons sur votre présence ...")
            .icon(BitmapDescriptorFactory
                    .defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
    map.animateCamera(CameraUpdateFactory.zoomTo(14), 2000, null);
}
}

试试这段代码

公共类行程活动扩展活动实现LocationListener{
公共静态最终双精度A=6372.8;//以公里为单位
私人静态最终车床事件地点=新车床(33.59648,-7.664723);
静态最终车床汉堡=新车床(53.558,9.927);
私人谷歌地图;
私人位置经理服务;
私人场所经理场所经理;
私有字符串提供者;
标记;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.mapevent);
findViewById(R.id.direction).setVisibility(View.INVISIBLE);
map=((MapFragment)getFragmentManager().findFragmentById(R.id.map))
.getMap();
map.setMapType(GoogleMap.map\u TYPE\u NORMAL);
Marker hamburg=map.addMarker(新MarkerOptions()
.职位(活动地点).标题(“我们的活动”)
.snippet(“我们正在等你…”);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(活动地点,15));
/**地理位置*/
服务=(位置管理器)getSystemService(位置服务);
布尔启用dgps=服务
.isprovidenabled(LocationManager.GPS\U提供商);
布尔值enabledWiFi=服务
.isProviderEnabled(LocationManager.NETWORK_提供商);
如果(!enabledGPS){
Toast.makeText(此“未找到GPS信号”,Toast.LENGTH\u LONG)
.show();
意向意向=新意向(设置、动作、位置、来源、设置);
星触觉(意向);
}
locationManager=(locationManager)此
.getSystemService(Context.LOCATION\u服务);
//
布尔启用=服务
.isprovidenabled(LocationManager.GPS\U提供商);
//主动式GPS
标准=新标准();
provider=locationManager.getBestProvider(条件,false);
Location Location=locationManager.getLastKnownLocation(提供者);
//初始化位置字段
如果(位置!=null){
Toast.makeText(此“选定的提供程序”+提供程序,
吐司。长度(短)。show();
onLocationChanged(位置);
新路由(此,地图,颜色。黑色)
.执行(
新车床(location.getLatitude(),location
.getLongitude()),事件位置);
}否则{
//做点什么
}
//初始化位置字段
}
已更改位置上的公共无效(位置){
//标记。删除();
双纬度=location.getLatitude();
double lng=location.getLongitude();
/*Toast.makeText(此“位置”+lat+,“+lng,Toast.LENGTH\u LONG)
.show()*/
LatLng坐标=新LatLng(lat,lng);
Toast.makeText(
这
“地点”
+坐标纬度
+ ","
+坐标经度
+“\n距离:”
+哈弗森(坐标.纬度,坐标.经度,
事件地点。纬度,事件地点。经度)
+“Km”,Toast.LENGTH_LONG)show();
Log.e(“lat+long”,String.valueOf(lat)+“/”+String.valueOf(lng));
地图。移动摄像机(摄像机更新工厂。新拉特朗格(新拉特朗格),
14));
如果(标记!=null){
标记。删除();
}
mark=map.addMarker(新的MarkerOptions()
.位置(新LatLng(lat,lng))
.标题(“你的名字”)
.snippet(“我们的康普顿河畔沃特河……”)
.图标(位图描述符工厂)
.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
animateCamera(CameraUpdateFactory.zoomTo(14),2000年,空);
}
@凌驾
公共无效onProviderDisabled(字符串提供程序){
//TODO自动生成的方法存根
Toast.makeText(此“已启用的新提供程序”+提供程序,
吐司。长度(短)。show();
}
@凌驾
公共无效onProviderEnabled(字符串提供程序){
//TODO自动生成的方法存根
Toast.makeText(此“禁用的提供程序”+提供程序,
吐司。长度(短)。show();
}
@凌驾
public void onStatusChanged(字符串提供程序、int状态、Bundle extra){
//TODO自动生成的方法存根
}
/*启动时请求更新*/
@凌驾
受保护的void onResume(){
super.onResume();
locationManager.RequestLocationUpdate(提供者,400,10,this);
}
/*活动暂停时删除locationlistener更新*/
@凌驾
受保护的void onPause(){
super.onPause();
locationManager.RemoveUpdate(此);
}
公共双哈弗赛因(双lat1、双lon1、双lat2、双lon2){
双dLat=数学托拉迪安(lat2-lat1);
双dLon=数学托拉迪安(lon2-lon1);
lat1=数学托拉迪安(lat1);
lat2=数学托拉迪安(lat2);
双a=Math.sin(dLat/2)*Math.sin(dLat/2)+Math.sin(dLon/2)
*数学正弦(dLon/2)*数学余弦(lat1)*数学余弦(lat2);
双c=2*Math.asin(Math.sqrt(a));
返回A*c;
}
}
试试这段代码

公共类行程活动扩展活动导入