谈到double,大多数人都知道,有朋友问double location,另外,还有人问locationmaster,这到底是咋回事?其实java return呢,下面是小编为大家整理的double location,跟我一起来看看吧~
double location
#include "iostream.h"
#include "math.h"
class Location {
private:
int x,y;
public:
Location(int i, int j):x(i),y(j) {}
int Getx( ) {return x;}
int Gety( ) {return y;}
double distance(Location b);
friend double distance(Location &a, Location &b);
};
double distance(Location &a, Location &b) //友元函数
{ int dx=a.x-b.x;
int dy=a.y-b.y;
return sqrt(dx*dx+dy*dy); }
double Location::distance(Location b) //成员函数
{ int dx=x-b.x;
int dy=y-b.y;
return sqrt(dx*dx+dy*dy); }
void main( )
{
Location A(-10,-20),B(-40,60);
cout<<"A("<<A.Getx( )<<","<<A.Gety( )<<"),B("<<B.Getx( )<<","<<B.Gety( )<<")"<<endl;
double d=A.distance(B); //调用成员函数
cout<<"Distance1= "<<d<<endl;
cout<<"Distance2= "<<distance(A,B)<<endl;} //调用友元函数
主程序中创建类location的两个对象A和B,A的坐标点设置方式如下:
android怎么把通过intent传递过来的double型经纬度放在location中啊!
个人感觉不会是你的latitude/longitude为空,你最好debug看看你的location是否为空。望有帮助。
Warning[Pe167]: argument of type "unsigned char *" is incompatible with parameter of type "char *"
碰到一模一样的问题哦,虽然简单,看都说的不清楚,补充下。
实参(argument)类型是指向 unsigned char 类型变量的指针,而形参(parameter)是指向char型变量的指针。
警告是说两者不相符。实际上,没有unsigned char型变量,应该是你自己定义的,只要将定义修改成 char即可。
LocationManager的getlastknownlocation方法是从哪里获取位置信息的?
貌似这个玩意是在locationmanagerservice里面一个成员变量保存的,在不同的locatuonprovider每次获取到地里位置时都会去保存一下。这个服务在启动后是一直运行的,也就是开机启动后这个变量才会有效。
求一个Android使用LocationManager获取两个点的经纬度之后计算出两个点的距离的Demo十万火急。
两点经纬度,计算距离
这种公式我必然是不知道的,谷歌翻了翻,有人(http://xxyyyboy.blog.163.com/blog/static/765832620110410457662/)说是
1.Lat1 Lung1 表示A点经纬度,Lat2 Lung2 表示B点经纬度;
2.a=Lat1 – Lat2 为两点纬度之差 b=Lung1 -Lung2 为两点经度之差;
3.6378.137为地球半径,单位为千米;
计算出来的结果单位为千米。
也有人(http://panyee.cnblogs.com/archive/2006/07/04/442771.html )说直接从google maps的脚本里扒了段代码。
我作为不明真相的群众就围观转一下maps的代码:计算的结果是米为单位。
// 计算两点距离
private final double EARTH_RADIUS = 6378137.0;
private double gps2m(double lat_a, double lng_a, double lat_b, double lng_b) {
double radLat1 = (lat_a * Math.PI / 180.0);
double radLat2 = (lat_b * Math.PI / 180.0);
double a = radLat1 - radLat2;
double b = (lng_a - lng_b) * Math.PI / 180.0;
double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
+ Math.cos(radLat1) * Math.cos(radLat2)
* Math.pow(Math.sin(b / 2), 2)));
s = s * EARTH_RADIUS;
s = Math.Round(s * 10000) / 10000;
return s;
}
设计一份坐标点类型,要求用友元函数完成。
#include "iostream.h" #include "math.h" class Location { private: int x,y; public: Location(int i, int j):x(i),y(j) {} int Getx( ) {return x;} int Gety( ) {return y;} double distance(Location b); friend double distance(Location &a, Location &b); }; double distance(Location &a, Location &b) //友元函数 { int dx=a.x-b.x; int dy=a.y-b.y; return sqrt(dx*dx+dy*dy); } double Location::distance(Location b) //成员函数 { int dx=x-b.x; int dy=y-b.y; return sqrt(dx*dx+dy*dy); } void main( ) { Location A(-10,-20),B(-40,60); cout<<"A("<<A.Getx( )<<","<<A.Gety( )<<"),B("<<B.Getx( )<<","<<B.Gety( )<<")"<<endl; double d=A.distance(B); //调用成员函数 cout<<"Distance1= "<<d<<endl; cout<<"Distance2= "<<distance(A,B)<<endl;} //调用友元函数
JAVA return div(value1,value2,location)中的location什么意思
这个DIV就是下面的那个方法啊public BigDecimal div(double value1, double value2, int b) {
},调用div方法返回div方法的返回值,location 就是你上面定义的值等于10
static final int location = 10;
自考C++方面的一些问题
#include "stdafx.h"
#include "math.h"
#include "stdlib.h"
#include "windows.h"
#define PI 3.1415926
//一.
class LOCATION
{
protected:
double x,y;
public:
virtual double getx()const{return x;}
virtual double gety()const{return y;}
virtual double dist(LOCATION &s) const;
LOCATION(){};
LOCATION(double x,double y):x(x),y(y){};
};
double LOCATION::dist(LOCATION &s) const
{
double xd=s.x-x, yd=s.y-y;
return sqrt(xd*xd+yd*yd);
}
class CIRCLE : public LOCATION
{
double r;
public:
double get_r() const {return r;}
double Girth() const {return 2*PI*r;}
double Area() const {return PI*r*r;}
CIRCLE();
CIRCLE(double x,double y,double r)
{this->x=x; this->y=y; this->r=r;}
};
//二.
class Shape {
public:
virtual double Area() = 0;
};
class Trapezoid : public Shape
{
public:
double x,y,h;
Trapezoid(double x,double y,double h):x(x),y(y),h(h){};
double Area() {return (x+y)*h*0.5;}
};
class Circle : public Shape
{
public:
double r;
Circle(double r):r(r) {};
double Area() { return PI*r*r; }
};
class Triangle : public Shape
{
public:
double x,y;
Triangle(double x,double y):x(x),y(y){};
double Area() { return x*y; }
};
//三.
template<class T> class Stack
{
T *x;
int size;
int current;
public:
Stack(int size)
{
this->size=size;
current=0;
x = new T[size];
}
~Stack(){ delete []x; }
BOOL push(const T &atom)
{
if(current<size)
{
x[current]=atom;
current++;
return TRUE;
}
else
return FALSE;
}
BOOL pop(T &atom)
{
if(current<size)
{
current--;
atom = x[current];
return TRUE;
}
else
return FALSE;
}
};
int main(int argc, char* argv[])
{
//一.
CIRCLE A(0,3,5), B(3,7,5);
printf("A:(%.f,%.f,%.f),Girth: %.2f, Area: %.2f ",A.getx(),A.gety(),A.get_r(),A.Girth(),A.Area());
printf("B:(%.f,%.f,%.f),Girth: %.2f, Area: %.2f ",B.getx(),B.gety(),B.get_r(),B.Girth(),B.Area());
double fBX=B.getx(),fBY=B.gety();
printf("A(%.f,%.f), B(%.f,%.f), Distance:%.2f ",A.getx(),A.gety(),fBX,fBY,A.dist(B));
printf(" ");
//二.
Trapezoid C(5,8,6);
Triangle D(6,8);
Circle E(10);
printf("Trapezoid:(%.f,%.f,%.f), Area: %.2f ",C.x,C.y,C.h,C.Area());
printf("Triangle:(%.f,%.f), Area: %.2f ",D.x,D.y,D.Area());
printf("Circle:(%.f), Area: %.2f ",E.r,E.Area());
//三.
Stack<int> s(10);
s.push(10);
int test=0;
s.pop(test);
printf("%d ",test);
system("pause");
return 0;
}
C++程序编写。。
#include<iostream>
#include<math.h>
class Location
{
public:
Location(double,double); //构造函数
double getx(); //成员函数,取x坐标值
double gety(); //成员函数,取y坐标值
double distance(Location &); //成员函数,求给定两点之间的距离
friend double distance(Location &,Location &); //友元函数,求给定两点之间的距离
private:
double x,y;
};
Location::Location(double x,double y)
{
this->x = x;
this->y = y;
}
double Location::getx()
{
return this->x;
}
double Location::gety()
{
return this->y;
}
double Location::distance(Location &locat)
{
double dis = 0.0;
dis = sqrt((this->x - locat.x)*(this->x - locat.x) + (this->y - locat.y)*(this->y - locat.y));
return dis;
}
double distance(Location &locat1,Location &locat2)
{
double dis = 0.0;
dis = sqrt((locat1.x - locat2.x)*(locat1.x - locat2.x) + (locat1.y - locat2.y)*(locat1.y - locat2.y));
return dis;
}
int _tmain(int argc, _TCHAR* argv[])
{
Location A(1.0, 2.0);
Location B(4.0, 6.0);
std::cout<<A.distance(B)<<std::endl;
std::cout<<distance(A,B)<<std::endl;
}
调试完毕,正确,至于输出的格式,按照你的需求自己改一下吧