是否可以在 android 中显示地图视图并允许用户选择一个区域,例如国家或州?
澄清:
我想让用户从地图视图中选择一个国家,这怎么可能?
我不关心所选国家是否突出显示,我只关心检索用户选择/触摸/标记的国家
是否可以在 android 中显示地图视图并允许用户选择一个区域,例如国家或州?
澄清:
我想让用户从地图视图中选择一个国家,这怎么可能?
我不关心所选国家是否突出显示,我只关心检索用户选择/触摸/标记的国家
有一种方法可以从地图中获取纬度,经度 如何从谷歌地图中获取经纬度触摸事件?
之后,您可以调用 Google Geo Code API 将此 lat,lon 转换为物理地址,
IE
http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true_or_false
上面的链接将返回 JSON
{
"status": "OK",
"results": [ {
"types": street_address,
"formatted_address": "275-291 Bedford Ave, Brooklyn, NY 11211, USA",
"address_components": [ {
"long_name": "275-291",
"short_name": "275-291",
"types": street_number
}, {
"long_name": "Bedford Ave",
"short_name": "Bedford Ave",
"types": route
}, {
"long_name": "New York",
"short_name": "New York",
"types": [ "locality", "political" ]
}, {
"long_name": "Brooklyn",
"short_name": "Brooklyn",
"types": [ "administrative_area_level_3", "political" ]
}, {
"long_name": "Kings",
"short_name": "Kings",
"types": [ "administrative_area_level_2", "political" ]
}, {
"long_name": "New York",
"short_name": "NY",
"types": [ "administrative_area_level_1", "political" ]
}, {
"long_name": "United States",
"short_name": "US",
"types": [ "country", "political" ]
}, {
"long_name": "11211",
"short_name": "11211",
"types": postal_code
} ],
"geometry": {
"location": {
"lat": 40.7142298,
"lng": -73.9614669
},
"location_type": "RANGE_INTERPOLATED",
"viewport": {
"southwest": {
"lat": 40.7110822,
"lng": -73.9646145
},
"northeast": {
"lat": 40.7173774,
"lng": -73.9583193
}
}
}
},
... Additional results[] ...
现在您可以解析 JSON 并获取国家名称城市名称地区、州等。
或者其他选择是只获取国家代码。
http://ws.geonames.org/countryCode?lat=25.03&lng=67.2
这将返回国家代码 PK = 巴基斯坦,您可以获取国家代码列表,或者
我知道的一种解决方案是,您可以通过地图图钉标记特定区域,并通过在 Map 中扩展 OverLay 类来填充该区域,如下所示。希望这是有用的。
public class MapOverlay extends Overlay
{
private GeoPoint new_geopoint = null;
public MapOverlay(GeoPoint geoPoint)
{
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow)
{
super.draw(canvas, mapView, shadow);
Paint mPaint = new Paint();
mPaint.setDither(true);
mPaint.setStyle(Style.FILL_AND_STROKE);
mPaint.setColor(Color.RED);
mPaint.setAlpha(9);
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(2);
Path path = new Path();
Projection projection = mapView.getProjection();
for(int j = 0; j < geoArrayist.size(); j++)
{
Iterator<GeoPoint> it = geoArrayist.iterator();
while(it.hasNext())
{
GeoPoint arrayListGeoPoint = it.next();
Point currentScreenPoint = new Point();
projection.toPixels(arrayListGeoPoint, currentScreenPoint);
if(j == 0)
path.moveTo(currentScreenPoint.x, currentScreenPoint.y);
else
path.lineTo(currentScreenPoint.x, currentScreenPoint.y);
}
}
// old_geopoint = new_geopoint;
canvas.drawPath(path, mPaint);
}
}