在谷歌地图android中默认显示特定国家/地区

时间:2017-01-12 11:05:37

标签: android google-maps

我们有什么方法可以将特定国家/地区显示为Google地图中的默认国家/地区?

我曾尝试过一些国家的中心,但这似乎很乏味。 我只有国家名称“印度”,我需要做的是,当应用程序开放时,将“印度”显示为焦点。

3 个答案:

答案 0 :(得分:0)

在您的onMapReady()函数集中

LatLngBounds boundsIndia = new LatLngBounds(new LatLng(23.63936, 68.14712), new LatLng(28.20453, 97.34466));
int padding = 0; // offset from edges of the map in pixels
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(boundsIndia, padding);
 mMap.animateCamera(cameraUpdate);

打开地图时,您只会在地图上看到印度国家。 您可以在其他任何国家/地区使用。

答案 1 :(得分:-1)

您可以使用Google地图Client-side Geocoder获取该国家/地区的边界框,如下例所示:

// API version 2
var geocoder = new GClientGeocoder();

geocoder.getLocations("Russia", function (locations) { 

    var north = locations.Placemark[0].ExtendedData.LatLonBox.north;
    var south = locations.Placemark[0].ExtendedData.LatLonBox.south;
    var east  = locations.Placemark[0].ExtendedData.LatLonBox.east;
    var west  = locations.Placemark[0].ExtendedData.LatLonBox.west;

    var bounds = new GLatLngBounds(new GLatLng(south, west), 
                                   new GLatLng(north, east));

    map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
});

// API version 3
// ... set north, south, east and west ...
var bounds = new google.maps.LatLngBounds(new google.maps.LatLng(south, west), 
                                          new google.maps.LatLng(north, east));
map.fitBounds(bounds);

这是您可以在代码中设置并自动进入该国家/地区的方式。我已经展示了俄罗斯,你可以改变你所在国家的坐标。

答案 2 :(得分:-2)

这显示悉尼并在其上放置一个标记https://developers.google.com/maps/documentation/android-api/map-with-marker

{{1}}
相关问题