How to launch map intent with a marker/overlay item at given latitude and longitude?

前端 未结 2 652
不知归路
不知归路 2021-02-03 14:21

I have a latitude and longitude and I want to open google maps centred at that point. So i use the following code for it:

Intent intent = new Intent(android.cont         


        
2条回答
  •  难免孤独
    2021-02-03 15:02

    You can simply put latitude and longitude as extras to the intent like this:

    Intent intent = new Intent();
        intent.putExtra("latitude", latitude);
        intent.putExtra("longitude", longitude);
        startActivity(intent);
    

    And then fetch them from the MapActivity you've started:

    Intent intent = getIntent();
        double latitude = intent.getDoubleExtra("latitude", 0.0);
        double longitude = intent.getDoubleExtra("longitude", 0.0);
    

    Then you can use those values for anything you want. Hope this helps.

提交回复
热议问题