使用按钮/Onclicklistener 打开 Google 地图应用的 Google 地图

Kod*_*211 0 android google-maps

我已经做了一个多星期了。我试过在我的应用程序中设置 Google 地图活动,但没有成功。我还看到您可以从您的应用程序调用 Google 地图应用程序。通过使用 Onclicklistener。如何使用按钮从我的应用程序打开 Google 地图应用程序?这是我正在使用的代码...

import com.google.android.maps.GeoPoint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Store10 extends Activity {

    Context context;
    GeoPoint geo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.store10);

        Button num10 = (Button) findViewById(R.id.pNumber10);
        Button nav10 = (Button) findViewById(R.id.Map10);

        num10.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                // TODO Auto-generated method stub
                Intent myIntent = new Intent(view.getContext() ,Num10.class);
                startActivityForResult(myIntent, 0);
            }
        });
        nav10.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                // TODO Auto-generated method stub
                String uri = String.format("geo:%f,%f",40,325874,76,002211);
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                context.startActivity(intent);
            }
        });
    }

}
Run Code Online (Sandbox Code Playgroud)

这是我正在尝试设置的 Onclicklistener

nav10.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                // TODO Auto-generated method stub
                String uri = String.format("geo:%f,%f",40,325874,76,002211);
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                context.startActivity(intent);
            }
        });
Run Code Online (Sandbox Code Playgroud)

vis*_*dra 5

你可以试试这行代码...

String uri = "http://maps.google.com/maps?saddr=" + "9982878"+","+"76285774"+"&daddr="+"9992084"+","+"76286455";
            Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
            intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
            startActivity(intent);  
Run Code Online (Sandbox Code Playgroud)