当前位置: 首页 > 知识库问答 >
问题:

将搜索参数从活动发送到google maps api(Android studio)

满子实
2023-03-14

首先,我只是想说我不是最擅长解释(也不擅长编程),所以请原谅我。

布局:

我有两个活动。第一个是一个复选框和一个按钮所在的主要活动。第二个活动是google maps API。

进展情况:

当我点击该按钮时,我进入google maps活动(使用intent)并有一个固定的位置。

private static Button button_Ok;
private static CheckBox bowling;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    onClickButtonListener();
}

public void onClickButtonListener() {
    button_Ok = (Button)findViewById(R.id.button);
    bowling = (CheckBox)findViewById(R.id.checkBox);
    button_Ok.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent("com.google.android.gms.maps.SupportMapFragment");
            startActivity(intent);
        }
    });
}
private void setUpMap() {
    mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
    mMap.setMyLocationEnabled(true);

    // Get LocationManager object from System Service LOCATION_SERVICE
    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    // Create a criteria object to retrieve provider
    Criteria criteria = new Criteria();

    // Get the name of the best provider
    String provider = locationManager.getBestProvider(criteria, true);

    // Get Current Location
    Location myLocation = locationManager.getLastKnownLocation(provider);

    // set map type
    mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);

    // Get latitude of the current location
    double latitude = *fixed*; //myLocation.getLatitude();

    // Get longitude of the current location
    double longitude = *fixed*; //myLocation.getLongitude();

    // Create a LatLng object for the current location
    LatLng latLng = new LatLng(latitude, longitude);

    // Show the current location in Google Map
    mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));

    // Zoom in the Google Map
    mMap.animateCamera(CameraUpdateFactory.zoomTo(14));
    mMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title("You are here!").snippet("Consider yourself located"));

    LatLng myCoordinates = new LatLng(latitude, longitude);
    CameraUpdate yourLocation = CameraUpdateFactory.newLatLngZoom(myCoordinates, 12);
    mMap.animateCamera(yourLocation);

    CameraPosition cameraPosition = new CameraPosition.Builder()
            .target(myCoordinates)      // Sets the center of the map to LatLng (refer to previous snippet)
            .zoom(13)                   // Sets the zoom
            .bearing(90)                // Sets the orientation of the camera to east
            .tilt(0)                   // Sets the tilt of the camera to 30 degrees
            .build();                   // Creates a CameraPosition from the builder
    mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

    // ... get a map.
    Circle circle = mMap.addCircle(new CircleOptions()
            .center(new LatLng(*fixed*, *fixed*))
            .radius(100)
            .strokeColor(Color.RED)
            .fillColor(Color.TRANSPARENT));


    mMap.getUiSettings().setZoomControlsEnabled(true);
}

}

我设置了fixed LatLng,因为get location函数似乎在仿真器上不起作用。

暂时还没有答案

 类似资料:
  • 问题内容: 我在通过Notification从服务向活动发送数据时遇到问题,我单击了一个活动被调用的通知,但是当我尝试通过捆绑包添加一些参数时,我无法获得所谓的intent中的参数,我经历了链接 如何将通知单击中的参数发送到活动? 但是仍然没有运气。 其他人也发生过同样的问题吗? 提前致谢。 问题答案: 您还必须修改清单文件。 这是有效的示例: 这些变量和方法是Service类的成员: 这是Mai

  • 问题内容: 我可以找到一种从通知中向活动发送参数的方法。 我有一个创建通知的服务。当用户单击通知时,我想使用一些特殊参数打开我的主要活动。例如,一个项目ID,这样我的活动就可以加载并显示一个特殊的项目详细信息视图。更具体地说,我正在下载文件,下载文件时,我希望通知具有以下意图:单击该通知后,它将以特殊模式打开我的活动。我曾尝试使用putExtra我的意图,但似乎无法提取它,因此我认为我做错了。 我

  • 我需要拍照并发送到主活动并发送到第三活动 这是MainActivity的代码 我有任何错误,但当我试图拍摄一张照片时,我得到这样的信息:不幸的是,第一相机停止了,我的问题是什么?

  • 我目前正在做一个项目,我需要帮助。 我想发送的名称,总数量和总价的一个产品的数量在我的添加到购物车活动。 @override public void onListClick(final ItemInfo item){ 上面应该有什么代码发送到购物车活动?? toast.maketext(mainactivity.this,“added To cart”,toast.length_short).sh

  • 我想在片段的活动中使用一些文本视图(cityField,updatedField)。我知道在活动中使用它们会更容易,但问题是,由于要获取一些JSON数据,我不得不在Fragment上加入一些代码 我已经得到了活动代码的ID 现在我想在我的片段中使用它们 所以问题是 - 这可能吗?如果可能,如何? 我已经检查了这个网站上的一些答案 - 在Android中将数据从活动发送到片段 如何使用捆绑包将数据从

  • 在我的应用程序中,我试图将数据从我的发送到一个名为的服务。这是我的以下代码: MainActivity.class: BGS服务。课程: 但我没有在服务类中获取数据。以下是我得到的错误: 02-25 09:05:41.166:E/AndroidRuntime(2633): JAVAlang.RuntimeException:无法启动活动 组件信息{com.microapple.googleplac