如何从地址中找到纬度和经度? [英] How can I find the latitude and longitude from address?

查看:40
本文介绍了如何从地址中找到纬度和经度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Google 地图中显示地址的位置.

I want to show the location of an address in Google Maps.

如何使用 Google Maps API 获取地址的纬度和经度?

How do I get the latitude and longitude of an address using the Google Maps API?

推荐答案

public GeoPoint getLocationFromAddress(String strAddress){

Geocoder coder = new Geocoder(this);
List<Address> address;
GeoPoint p1 = null;

try {
    address = coder.getFromLocationName(strAddress,5);
    if (address==null) {
       return null;
    }
    Address location=address.get(0);
    location.getLatitude();
    location.getLongitude();

    p1 = new GeoPoint((double) (location.getLatitude() * 1E6),
                      (double) (location.getLongitude() * 1E6));

    return p1;
    }
}

strAddress 是一个包含地址的字符串.address 变量保存转换后的地址.

strAddress is a string containing the address. The address variable holds the converted addresses.

这篇关于如何从地址中找到纬度和经度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆