是否可以在android中显示地图视图,允许用户选择某个区域,例如国家或州?
澄清:
我想让用户从地图视图中选择一个国家/地区,这怎么可能?
我不关心所选国家/地区是否突出显示,我只关心检索用户选择/触摸/标记的国家/地区
答案 0 :(得分:3)
有一种方法可以从地图中获取lat,lon how to get lat and long on touch event from google map?
之后,您可以调用Google Geo Code API将此lat,lon转换为物理地址
即。
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 =巴基斯坦 您可以获得国家/地区代码列表,或
答案 1 :(得分:1)
我知道的一个解决方案是你可以通过地图引脚标记特定区域,并通过在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);
}
}