Swift,谷歌地图适合所有标记

时间:2015-08-13 07:51:07

标签: ios swift google-maps

我希望使用自动缩放功能在Google地图窗口中显示所有标记。

以下是我的代码

    private class SignInOnClickListener implements View.OnClickListener {

    public void onClick(View v) {
        // Get the username and password from the view
        final String username_email = mUsernameEmailEtxt.getText().toString().toLowerCase().trim();
        final String password = mPasswordEtxt.getText().toString().trim();
        if (isFormInputValid(username_email, password)) {
            if (username_email.indexOf('@') != -1) {
                ParseQuery<ParseUser> query = ParseUser.getQuery();
                query.whereEqualTo("email", username_email);
                query.getFirstInBackground(new GetCallback<ParseUser>() {
                    public void done(ParseUser object, ParseException e) {
                        if (object == null) {
                            TextView error = (TextView) findViewById(R.id.error);
                            error.setVisibility(View.VISIBLE);
                            error.setText(getString(R.string.error_sign_in));

                            Log.d("error", "The getFirst request failed. Probably because no associated account found");
                        } else {
                            String actualUsername = (String) object.get("username");
                            ParseUser.logInInBackground(actualUsername, password, new LogInCallback() {
                                public void done(ParseUser user, ParseException e) {
                                    if (user != null) {
                                        // Hooray! The user is logged in.
                                        Intent intent = new Intent(getBaseContext(), MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                                        startActivity(intent);
                                        finish();
                                    } else {
                                        TextView error = (TextView) findViewById(R.id.error);
                                        error.setVisibility(View.VISIBLE);
                                        error.setText(getString(R.string.error_sign_in));

                                        Log.d("error", "email or password  invalid");
                                    }
                                }
                            });
                        }
                    }
                });

            } else {
                Log.d("detector", "username_email detected as username:" + username_email);
                ParseUser.logInInBackground(username_email, password, new LogInCallback() {
                    public void done(ParseUser user, ParseException e) {
                        if (user != null) {
                            // Hooray! The user is logged in.
                            Intent intent = new Intent(getBaseContext(), MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            startActivity(intent);
                            finish();
                        } else {
                            TextView error = (TextView) findViewById(R.id.error);
                            error.setVisibility(View.VISIBLE);
                            error.setText(getString(R.string.error_sign_in));

                            Log.d("error", "username or password invalid");
                        }

                    }
                });
            }
        }
    }
}

在视图willappear和viewdidload方法上添加了上面的swift代码。 有人可以帮助我在上面的代码中解决我的错误。

1 个答案:

答案 0 :(得分:10)

@IBOutlet weak var viewMap: GMSMapView!
var markers = [GMSMarker]()
var bounds = GMSCoordinateBounds()
    for marker in self.markers {
        bounds = bounds.includingCoordinate(marker.position)
    }
    viewMap.animate(with: GMSCameraUpdate.fit(bounds, with: UIEdgeInsetsMake(50.0 , 50.0 ,50.0 ,50.0)))