经纬度定位java代码,java 经纬度
java代码实现如何获取当前经纬度?
安卓的话可以用GPS取。
成都创新互联公司是一家网站设计公司,集创意、互联网应用、软件技术为一体的创意网站建设服务商,主营产品:自适应网站建设、成都品牌网站建设、成都全网营销推广。我们专注企业品牌在网站中的整体树立,网络互动的体验,以及在手机等移动端的优质呈现。网站建设、成都网站设计、移动互联产品、网络运营、VI设计、云产品.运维为核心业务。为用户提供一站式解决方案,我们深知市场的竞争激烈,认真对待每位客户,为客户提供赏析悦目的作品,网站的价值服务。
import android.app.Activity;
import android.os.Bundle;
import android.location.*;
import android.content.*;
import android.util.Log;
import android.widget.TextView;
public class GPSLocationListenActivity extends Activity implements LocationListener {
LocationManager locman;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
locman = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
}
@Override
protected void onResume(){
if (locman != null){
locman.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,0,this);
}
super.onResume();
}
@Override
protected void onPause(){
if (locman != null){
locman.removeUpdates(this);
}
super.onPause();
}
@Override
public void onLocationChanged(Location location){
TextView textView1 = (TextView)findViewById(R.id.textView1);
textView1.setText("Latitude:Longitude - "
+String.valueOf(location.getLatitude()) +":"+String.valueOf(location.getLongitude()));
TextView textView2 = (TextView)findViewById(R.id.textView2);
textView2.setText(String.valueOf(location.getTime()));
Log.v("----------", "----------");
Log.v("Latitude", String.valueOf(location.getLatitude()));
Log.v("Longitude", String.valueOf(location.getLongitude()));
Log.v("Accuracy", String.valueOf(location.getAccuracy()));
Log.v("Altitude", String.valueOf(location.getAltitude()));
Log.v("Time", String.valueOf(location.getTime()));
Log.v("Speed", String.valueOf(location.getSpeed()));
Log.v("Bearing", String.valueOf(location.getBearing()));
}
@Override
public void onProviderDisabled(String provider){
}
@Override
public void onProviderEnabled(String provider){
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras){
switch(status){
case LocationProvider.AVAILABLE:
Log.v("Status","AVAILABLE");
break;
case LocationProvider.OUT_OF_SERVICE:
Log.v("Status","OUT_OF_SERVICE");
break;
case LocationProvider.TEMPORARILY_UNAVAILABLE:
Log.v("Status","TEMPORARILY_UNAVAILABLE");
break;
}
}
}
求JAVA经纬度转换代码
由于键盘上没有 ° 键,所以我在程序中把它换成 * 键了。
运行下面程序,从控制台输入 40582974 ,回车 ,输出结果:22*32.7658′
若
输入:57335948
则
输出:31*51.1983'
import java.math.BigDecimal;
import java.util.Scanner;
public class LatitudeTransform {
public static void main(String[] args) {
Scanner sca = new Scanner(System.in);
String in = sca.nextLine();
//将控制台接收到的输入转成数字
long num = Long.parseLong(in);
//利用整除舍弃余数得到度数值
long du = (num / 30000) / 60;
//将控制台接收到的数值除以30000,得到度和分的混合结果,再对60取余,得到分的部分
BigDecimal fen = new BigDecimal(num).divide(new BigDecimal(30000), 4, BigDecimal.ROUND_HALF_UP).remainder(
new BigDecimal(60));
System.out.println(du + "*" + fen + "'");
}
}
下面的部分是,在控制台输入22°32.7658′ ,回车得到40582974。开始的时候读你的问题理解反了,所以先写的这个,也给你吧,要是没用就算了~呵呵。
import java.util.Scanner;
public class LatitudeTransform {
public static void main(String[] args) {
Scanner sca = new Scanner(System.in);
String in = sca.nextLine();
String result = transform(in);
System.out.println(result);
}
private static String transform(String in) {
//将输入的字符串分成两截,分别为度数du_string,分数fen_string
String du_string = in.substring(0, in.indexOf("*"));
//substring方法两个参数遵循规则"前包含后不包含",例,”1234“.substring(0,2)返回的结果是index为0到1的子串,即"12"
String fen_string = in.substring(in.indexOf("*") + 1, in.indexOf("'"));
double du = Double.parseDouble(du_string);
double fen = Double.parseDouble(fen_string);
Long result = (long) ((du * 60 + fen) * 30000);
return result.toString();
}
}
经纬度转平面坐标系java代码
定一个原点。 定一个比例尺 然后根据点与原点的距离,得到坐标,再通过与原点的坐标比,得到距离,再转成经纬度
求java代码,手机获取当前GPS的经纬度。
记得我前几天发过一个类似的代码如下(适用安卓)
import android.app.Activity;
import android.os.Bundle;
import android.location.*;
import android.content.*;
import android.util.Log;
import android.widget.TextView;
public class GPSLocationListenActivity extends Activity implements LocationListener {
LocationManager locman;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
locman = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
}
@Override
protected void onResume(){
if (locman != null){
locman.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,0,this);
}
super.onResume();
}
@Override
protected void onPause(){
if (locman != null){
locman.removeUpdates(this);
}
super.onPause();
}
@Override
public void onLocationChanged(Location location){
TextView textView1 = (TextView)findViewById(R.id.textView1);
textView1.setText("Latitude:Longitude - "
+String.valueOf(location.getLatitude()) +":"+String.valueOf(location.getLongitude()));
TextView textView2 = (TextView)findViewById(R.id.textView2);
textView2.setText(String.valueOf(location.getTime()));
Log.v("----------", "----------");
Log.v("Latitude", String.valueOf(location.getLatitude()));
Log.v("Longitude", String.valueOf(location.getLongitude()));
Log.v("Accuracy", String.valueOf(location.getAccuracy()));
Log.v("Altitude", String.valueOf(location.getAltitude()));
Log.v("Time", String.valueOf(location.getTime()));
Log.v("Speed", String.valueOf(location.getSpeed()));
Log.v("Bearing", String.valueOf(location.getBearing()));
}
@Override
public void onProviderDisabled(String provider){
}
@Override
public void onProviderEnabled(String provider){
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras){
switch(status){
case LocationProvider.AVAILABLE:
Log.v("Status","AVAILABLE");
break;
case LocationProvider.OUT_OF_SERVICE:
Log.v("Status","OUT_OF_SERVICE");
break;
case LocationProvider.TEMPORARILY_UNAVAILABLE:
Log.v("Status","TEMPORARILY_UNAVAILABLE");
break;
}
}
}
之前的提问链接
网页名称:经纬度定位java代码,java 经纬度
本文路径:http://azwzsj.com/article/hdijio.html