成都网站建设设计

将想法与焦点和您一起共享

经纬度android,经纬度查询定位

百度地图android中怎么通过地址获取经纬度

在百度地图开发的时候,我们经常会通过地址去得到当前地址的经纬度,方法如下:

创新互联于2013年成立,先为裕安等服务建站,裕安等地企业,进行企业商务咨询服务。为裕安企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

方法一、

public GeoPoint getGeoPointBystr(String str) {

GeoPoint gpGeoPoint = null;

if (str!=null) {

Geocoder gc = new Geocoder(MyMapActivity.this,Locale.CHINA);

ListAddress addressList = null;

try {

addressList = gc.getFromLocationName(str, 1);

if (!addressList.isEmpty()) {

Address address_temp = addressList.get(0);

//计算经纬度

double Latitude=address_temp.getLatitude()*1E6;

double Longitude=address_temp.getLongitude()*1E6;

System.out.println("经度:"+Latitude);

System.out.println("纬度:"+Longitude);

//生产GeoPoint

gpGeoPoint = new GeoPoint((int)Latitude, (int)Longitude);

}

} catch (IOException e) {

e.printStackTrace();

}

}

return gpGeoPoint;

}

此方法只需传入一个地址即可(当然,这里应该说是一个合法的地址)

此方法得到一个GeoPoint对象,通过GeoPoint对象.getLatitude()/getLongitude()就可以得到对应的经纬度

但是值得注意的是,以上方法存在API版本问题,2.2版本的不可以用

方法二、(个人比较推荐这种方法)

mkSearch.geocode("详细地址", "城市");

这里的详细地址可以通过MKSuggestionInfo对象.key得到,而城市也可以根据MKSuggestionInfo对象.city得到

调用以上方法后,就会在执行实现MKSearchListener接口类中的以下方法

public void onGetAddrResult(MKAddrInfo info, int error) {

// TODO Auto-generated method stub

System.out.println("经纬度:"+info.geoPt.getLatitudeE6()+" "+info.geoPt.getLongitudeE6());

}

这样就可以得到了经纬度

怎么在android百度地图通过经纬度来定位并且显示出地图位置

1、设置AndroidManfest.xml权限ViewCode2、配置jar包3、初始化设置BMapManagerViewCodemapManager=newBMapManager(this);mapManager.init("EDB67AD764D300895C95ABA02A4DDC58D5485CCD",newMyMKGeneralListener());//设置通知间隔:iMaxSecond-最大通知间隔,单位:秒;iMinSecond-最小通知间隔,单位:秒mapManager.getLocationManager().setNotifyInternal(20,5);4、获取手机经纬度,并显示地址信息ViewCodemapManager.getLocationManager().requestLocationUpdates(newMyLocationListener());mapManager.start();在LocationListener中获取经纬度ViewCodeclassMyLocationListenerimplementsLocationListener{@OverridepublicvoidonLocationChanged(Locationarg0){intjindu=(int)(arg0.getLatitude()*1000000);intweidu=(int)(arg0.getLongitude()*1000000);tv1.setText("经度:"+jindu+",纬度:"+weidu);MKSearchsearch=newMKSearch();search.init(mapManager,newMyMKSearchListener());search.reverseGeocode(newGeoPoint(jindu,weidu));}}在MKSearch接口中进行地址转化

Android 上面有哪些方法可以获取经纬度

编程方面:1,:可以使用Android自带的LocationManager获取,2:可以根据API获取经纬度(一般用的较多的为百度地图API)

应用方面:1:手机自带的指南针,2:地图软件(高德、百度等)

android中怎么获取经纬度

在Android应用程序中,可以使用LocationManager来获取移动设备所在的地理位置信息。看如下实例:新建android应用程序TestLocation。

1、activity_main.xml布局文件

[html] view plain copy

print?

LinearLayout xmlns:android=""

android:layout_width="fill_parent"

android:layout_height="fill_parent"

TextView

android:id="@+id/positionView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

/

/LinearLayout

用于显示获取到的位置信息。

2、MainActivity.Java

[java] view plain copy

print?

package com.example.testlocation;

import java.util.List;

import android.app.Activity;

import android.content.Context;

import android.location.Location;

import android.location.LocationListener;

import android.location.LocationManager;

import android.os.Bundle;

import android.view.Menu;

import android.widget.TextView;

import android.widget.Toast;

public class MainActivity extends Activity {

private TextView postionView;

private LocationManager locationManager;

private String locationProvider;

@Override

protected void onCreate(Bundle savedInstanceState) {


当前标题:经纬度android,经纬度查询定位
本文地址:http://chengdu.cdxwcx.cn/article/dscddcj.html