2017-01-02 62 views

回答

7

关于在谷歌地图API的国家或其他特征的边界问题被问了很多次,但是,遗憾的是谷歌不公开公开此数据。

要突出显示该国家,您应该将自己的数据作为Google地图图层应用。尼斯的工作围绕在以下答案

https://stackoverflow.com/a/40172098/5140781

您可以从OSM下载国界在GeoJSON格式导出建议。之后,您可以使用Google Maps Android API Utility Library在您的应用程序中添加GeoJsonLayer

对于我的示例,我以GeoJSON格式下载了西班牙的边界,并使用GeoJsonLayer加载了GeoJSON文件。

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { 

    private GoogleMap mMap; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_maps); 
     // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
     SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
       .findFragmentById(R.id.map); 
     mapFragment.getMapAsync(this); 
    } 

    @Override 
    public void onMapReady(GoogleMap googleMap) { 
     mMap = googleMap; 

     mMap.getUiSettings().setZoomControlsEnabled(true); 

     LatLng madrid = new LatLng(40.416775,-3.70379); 
     mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(madrid, 3F)); 

     try { 
      GeoJsonLayer layer = new GeoJsonLayer(mMap, R.raw.es_geojson, getApplicationContext()); 

      GeoJsonPolygonStyle style = layer.getDefaultPolygonStyle(); 
      style.setFillColor(Color.MAGENTA); 
      style.setStrokeColor(Color.MAGENTA); 
      style.setStrokeWidth(1F); 

      layer.addLayerToMap(); 

     } catch (IOException ex) { 
      Log.e("IOException", ex.getLocalizedMessage()); 
     } catch (JSONException ex) { 
      Log.e("JSONException", ex.getLocalizedMessage()); 
     } 
    } 
} 

您可以从GitHub上的完整的示例项目,不要忘记改变值API密钥/ google_maps_api.xml

https://github.com/xomena-so/so41431384

enter image description here

我希望这有助于!