Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.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
android方法(之间的距离()) 在此处输入代码 包tryanabtry.opa; 导入java.util.List; 导入android.content.Context; 导入android.graphics.drawable.drawable; 导_Android_Location - Fatal编程技术网

android方法(之间的距离()) 在此处输入代码 包tryanabtry.opa; 导入java.util.List; 导入android.content.Context; 导入android.graphics.drawable.drawable; 导

android方法(之间的距离()) 在此处输入代码 包tryanabtry.opa; 导入java.util.List; 导入android.content.Context; 导入android.graphics.drawable.drawable; 导,android,location,Android,Location,android方法(之间的距离()) 在此处输入代码 包tryanabtry.opa; 导入java.util.List; 导入android.content.Context; 导入android.graphics.drawable.drawable; 导入android.location.location; 导入android.location.LocationListener; 导入android.location.LocationManager; 导入android.os.Bundle;

android方法(之间的距离())
在此处输入代码
包tryanabtry.opa;
导入java.util.List;
导入android.content.Context;
导入android.graphics.drawable.drawable;
导入android.location.location;
导入android.location.LocationListener;
导入android.location.LocationManager;
导入android.os.Bundle;
导入android.util.Log;
导入android.widget.Toast;
导入com.google.android.maps.GeoPoint;
导入com.google.android.maps.MapActivity;
导入com.google.android.maps.MapController;
导入com.google.android.maps.MapView;
导入com.google.android.maps.Overlay;
导入com.google.android.maps.OverlayItem;
公共类tryanabtry扩展了MapActivity{
私有地图视图;
专用地图控制器;
地质点p、p2、p3、p4;
列出地图覆盖图;
可拉伸,可拉伸2,可拉伸3,可拉伸4;
HelloItemizedOverlay itemizedOverlay,itemizedOverlay2,itemizedOverlay3,itemizedOverlay4;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState)
{
试一试{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*使用LocationManager类获取GPS位置*/
LocationManager mlocManager=(LocationManager)getSystemService(Context.LOCATION\u服务);
LocationListener mlocListener=新建MyLocationListener();
mlocManager.RequestLocationUpdate(LocationManager.GPS_提供程序,0,0,mlocListener);
mapView=(mapView)findViewById(R.id.mapView);
//默认情况下启用街景
mapView.setStreetView(真);
mapView.SetBuilTinZoomControl(真);
mc=mapView.getController();
mc.setZoom(12);
addOverLays();
}
捕获(例外e){
Log.d(“eeeeeeee”,e.getMessage());
}
}
公共void addOverLays(){
字符串[]坐标={“31.21648728475037”、“29.93263721460645”、“30.084123015403748”、“51.5002”、“-0.1262”、“31.33714914328994”};
双lat=31.21648728475037;//lat2=51.5002,lat3=29.987091422080994;
双对数=29.93263721460645;//log2=-0.1262,log3=31.439094546703;
p=新的地质点((内部)(纬度*1E6),(内部)(对数*1E6));
//p2=新的地质点((内部)(lat2*1e6),(内部)(log2*1e6));
//p3=新的地质点((内部)(lat3*1e6),(内部)(log3*1e6));
mapOverlays=mapView.getOverlays();
drawable=this.getResources().getDrawable(R.drawable.ballon);
//drawable2=this.getResources().getDrawable(R.drawable.ballon);
//drawable3=this.getResources().getDrawable(R.drawable.ballon);
itemizedOverlay=新的HelloItemizedOverlay(可绘制,此);
//itemizedOverlay2=新的HelloItemizedOverlay(可绘图2,本);
//itemizedOverlay3=新的HelloItemizedOverlay(可绘图3,本);
OverlayItem OverlayItem=新的OverlayItem(p,“Cairo”,“over1”);
//OverlayItem over2=新的OverlayItem(p2,“ulm”,“over2”);
//OverlayItem over3=新的OverlayItem(p3,“offff”,“over3”);
itemizedOverlay.addOverlay(overlayitem);
添加(itemizedOverlay);
//项目化覆盖2.添加覆盖(超过2);
//添加(itemizedOverlay2);
//项目化覆盖3.添加覆盖(超过3);
//添加(itemizedOverlay3);
mc.setZoom(17);
//司马迁(p),;
}
/*类我的位置侦听器*/
公共类MyLocationListener实现LocationListener
{
@凌驾
位置更改后的公共无效(位置loc)
{
地质点=新的地质点((int)(位置getLatitude()*1E6),
(int)(loc.getLongitude()*1E6));
//DoubletoString(loc.getLatitude());
//DoubletoString(loc.getLongitude());
///////////////////////////////////////////////////
loc.getaccurity();
////////////////////////////////////////////////////////////
String Text=“我的当前位置是:”+
“Latitud=“+loc.getLatitude()+
“Longitud=“+loc.getlongitud();
Toast.makeText(getApplicationContext(),
文本
吐司。长度(短)。show();
司仪(点),;
///////////////////////////////////////7电热水器拆除
///////////////如果(点==p){
///////////////getOverlays().remove(p);
////////////////// }
}
专用双距离(双lat1、双lon1、双lat2、双lon2、字符单位){
位置loc=空;
地质点=新的地质点((int)(位置getLatitude()*1E6),
(int)(loc.getLongitude()*1E6));
lat1=loc.getLatitude();
lon1=loc.getLongitude();
lat2=31.21648728475037;
lon2=29.93263721460645;
双θ=lon1-lon2;
双区=数学sin(deg2rad(lat1))*数学sin(deg2rad(lat2))+数学cos(deg2rad(lat1))*数学cos(deg2rad(lat2))*数学cos(deg2rad(theta));
dist=数学acos(dist);
dist=rad2deg(dist);
dist=dist*60*1.1515;
如果(单位='K'){
dist=dist*1.609344;
}否则,如果(单位='N'){
dist=dist*0.8684;
}
返回(dist);
}
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::此函数用于将十进制度数转换为弧度:
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
专用双deg2rad(双deg){
返回值(deg*Math.PI/180.0);
}
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::此函数用于将弧度转换为十进制度数:
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
专用双rad2deg(双rad){
返回值(rad/Math.PI*180.0);
}
私有void DoubletoString(双纬度){
//TODO自动生成的方法存根
}
公共无效onProviderDisabled(字符串提供程序)
{
Toast.makeText(getApplicationContext(),
“Gps禁用”,
Toast.LENGTH_SHORT).show();
}
公共无效onProviderEnabled(字符串提供程序)
{
Toast.makeText(getApplicationContext(),
“启用Gps”,
吐司。长度(短)。show();
}
public void onStatusChanged(字符串提供程序、int状态、Bundle extra)
{
}
受保护的布尔值isRouteDisplayed(){
返回false;
}
}/*MyLocationListener类结束*/
@凌驾
受保护的布尔值isRouteDisplayed(){
//TODO自动生成的方法存根
返回fal
 enter code here

 package tryanabtry.opa;
 import java.util.List;
 import android.content.Context;


import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;


 public class tryanabtry extends MapActivity{
private MapView mapView;
private MapController mc;

GeoPoint p, p2, p3, p4;
List<Overlay> mapOverlays;
Drawable drawable, drawable2 , drawable3, drawable4;
HelloItemizedOverlay itemizedOverlay, itemizedOverlay2 , itemizedOverlay3,    itemizedOverlay4;

    /** Called when the activity is first created. */

     @Override

        public void onCreate(Bundle savedInstanceState)

         {
          try{
       super.onCreate(savedInstanceState);

       setContentView(R.layout.main);


       /* Use the LocationManager class to obtain GPS locations */

      LocationManager mlocManager =    (LocationManager)getSystemService(Context.LOCATION_SERVICE);

  LocationListener mlocListener = new MyLocationListener();

  mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
   mapView = (MapView) findViewById(R.id.mapView);

   // enable Street view by default
    mapView.setStreetView(true);


     mapView.setBuiltInZoomControls(true);

         mc = mapView.getController();

      mc.setZoom(12); 
         addOverLays();
           }
         catch(Exception e){
Log.d("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",e.getMessage());
}
}
public void addOverLays(){
String [] coordinates = {"31.216487288475037","29.932637214660645" ,"30.084123015403748", "51.5002" , "-0.1262","31.337149143218994"};
double lat = 31.216487288475037;//lat2 = 51.5002,lat3=29.987091422080994;
double log = 29.932637214660645;// log2 = -0.1262,log3=31.43909454345703;

p = new GeoPoint((int) (lat * 1E6), (int) (log * 1E6));
// p2 = new GeoPoint( (int) (lat2 * 1e6), (int) (log2 * 1e6));
// p3=new GeoPoint( (int) (lat3 * 1e6), (int) (log3 * 1e6));
mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.ballon);
//drawable2 = this.getResources().getDrawable(R.drawable.ballon);
// drawable3 = this.getResources().getDrawable(R.drawable.ballon);

itemizedOverlay = new HelloItemizedOverlay(drawable,this);
//  itemizedOverlay2 = new HelloItemizedOverlay(drawable2,this);        
//  itemizedOverlay3 = new HelloItemizedOverlay(drawable3,this);    
OverlayItem overlayitem = new OverlayItem(p, "Cairo", " over1");
//  OverlayItem over2 = new OverlayItem(p2, "ulm", "over2");
//OverlayItem over3 = new OverlayItem(p3, "offff", "over3");

itemizedOverlay.addOverlay(overlayitem);

mapOverlays.add(itemizedOverlay);

// itemizedOverlay2.addOverlay(over2);
// mapOverlays.add(itemizedOverlay2);

// itemizedOverlay3.addOverlay(over3);
//   mapOverlays.add(itemizedOverlay3);
mc.setZoom(17); 
// mc.animateTo(p);
}


/* Class My Location Listener */



public class MyLocationListener implements LocationListener

{

@Override

public void onLocationChanged(Location loc)

{





GeoPoint point = new GeoPoint(    (int) (loc.getLatitude() * 1E6), 
        (int) (loc.getLongitude() * 1E6));
//DoubletoString(loc.getLatitude());

//DoubletoString(loc.getLongitude());
///////////////////////////////////////////////////
loc.getAccuracy();
////////////////////////////////////////////////////////////
String Text = "My current location is: " +

"Latitud ="+ loc.getLatitude() +

"Longitud =" + loc.getLongitude();



Toast.makeText( getApplicationContext(),

Text,

Toast.LENGTH_SHORT).show();
mc.animateTo(point);
///////////////////////////////////////7ewar el remove 

///////////////if (point ==p){
///////////////mapView.getOverlays().remove(p);
////////////////// }

}

      private double distance(double lat1, double lon1, double lat2, double lon2, char  unit) {
   Location loc = null;
        GeoPoint point = new GeoPoint(    (int) (loc.getLatitude() * 1E6), 
        (int) (loc.getLongitude() * 1E6));
       lat1=loc.getLatitude();
       lon1=loc.getLongitude();
       lat2= 31.216487288475037;
       lon2=29.932637214660645;
   double theta = lon1 - lon2;
   double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) +       Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
    dist = Math.acos(dist);
  dist = rad2deg(dist);
  dist = dist * 60 * 1.1515;
  if (unit == 'K') {
    dist = dist * 1.609344;
  } else if (unit == 'N') {
    dist = dist * 0.8684;
    }
  return (dist);
}

//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::  This function converts decimal degrees to radians             :::
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
private double deg2rad(double deg) {
  return (deg * Math.PI / 180.0);
}

//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::  This function converts radians to decimal degrees             :::
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
private double rad2deg(double rad) {
  return (rad / Math.PI * 180.0);
}

private void DoubletoString(double latitude) {
// TODO Auto-generated method stub

}


public void onProviderDisabled(String provider)

{

Toast.makeText( getApplicationContext(),

"Gps Disabled",

Toast.LENGTH_SHORT ).show();

}


public void onProviderEnabled(String provider)

{

Toast.makeText( getApplicationContext(),

"Gps Enabled",

Toast.LENGTH_SHORT).show();

}


public void onStatusChanged(String provider, int status, Bundle extras)

{


}

protected boolean isRouteDisplayed() {
return false;
}

}/* End of Class MyLocationListener */


@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}


}


/* End of UseGps Activity*/