android:google map api总是从非洲开始显示

时间:2016-02-21 13:00:50

标签: android google-maps-android-api-2

我正在使用地图片段来显示地图。但是当地图开始时它显示在非洲的某个位置然后转移到我想要的地方。我在stackoverflow中尝试了一些解决方案,它没有用,它仍然从非洲开始

mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(26.588527, 77.519531), 4));

另一种解决方案:

$scope.fileUpload = function (files) {
                angular.forEach(files, function () {
                    var fd = new FormData();
                    fd.append('files[]', files[0]);

                    var xhr = new XMLHttpRequest();

                    xhr.upload.onprogress = function (event) {
                        $scope.progress = Math.floor((event.loaded / event.total) * 100);
                        console.log(event.loaded + ' / ' + event.total);
                    }

                    xhr.open("POST", '/my-url', true);
                    xhr.send(fd);
                });
            };

3 个答案:

答案 0 :(得分:1)

您可以配置initial map state

使用cameraTargetLatcameraTargetLngcameraZoom XML属性,例如:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    map:cameraTargetLat="26.588527"
    map:cameraTargetLng="77.519531"
    map:cameraZoom="4"/>

以编程方式使用GoogleMapOptions,例如:

CameraPosition indiaPosition = new CameraPosition.Builder()
    .target(new LatLng(26.588527, 77.519531))
    .zoom(4)
    .build();

GoogleMapOptions mapOptions = new GoogleMapOptions().camera(camera)

SupportMapFragment map = SupportMapFragment.newInstance(mapOptions);

答案 1 :(得分:1)

试试这个:

//setting India region in google maps
LatLngBounds INDIA = new LatLngBounds(
        new LatLng(7.2, 67.8), new LatLng(36.5, 93.8));

map.moveCamera(CameraUpdateFactory.newLatLngZoom(INDIA.getCenter(), 5));

这将使印度地区成为地图。

答案 2 :(得分:0)

试试这个:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app"> 
    <form name="myForm" ng-controller="ctrl" novalidate><!-- mandatory -->
    <button ng-disabled="myForm.$invalid">Save</button>
    
    <table>
      <tr ng-repeat="item in items" ng-form="myForm">
        <td>
          <input type="text" name="{{'description'+$index}}" ng-model="item.description" required/>
        </td>
      </tr>
    </table>

    </form>
  </div>

效果很好!!