Android 谷歌地图使用按钮/Onclicklistener打开谷歌地图应用程序

Android 谷歌地图使用按钮/Onclicklistener打开谷歌地图应用程序,android,google-maps,Android,Google Maps,我已经做了一个多星期了。我尝试在我的应用程序中设置谷歌地图活动,但没有成功。我还看到你可以从你的应用程序中调用谷歌地图应用程序。通过使用onclick侦听器。如何使用按钮从我的应用程序打开谷歌地图应用程序?这是我正在使用的代码 import com.google.android.maps.GeoPoint; import android.app.Activity; import android.content.Context; import android.content.Intent; imp

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

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);
            }
        });
    }

}
这是我要设置的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);
            }
        });
//---显示地图按钮---

请检查此URL,可能会对您有所帮助

Uri uri = Uri.parse("geo:13.070984,80.253639");
Intent in = new Intent(Intent.ACTION_VIEW, uri);
startActivity(in);

更改Uri以设置缩放级别

uri = Uri.parse("geo:37.827500,-122.481670"?z=10"); 
尝试以下操作以添加标记:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<lat>,<long>?q=<lat>,<long>(Label+Name)"));
startActivity(intent);
Intent-Intent=newintent(Intent.ACTION_视图,Uri.parse(“geo:,?q=,(Label+Name)”);
星触觉(意向);

如果您不想要标签,可以省略(标签+名称),它会根据最近的街道或其他它认为相关的东西随机选择一个标签。

您可以尝试以下代码行

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);  

我就是这样做的

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(
"geo:"    + marker.getPosition().latitude +
","       + marker.getPosition().longitude +
"?q="     + marker.getPosition().latitude +
","       + marker.getPosition().longitude +                                   
"("       + marker.getTitle() + ")"));

intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);

OnClick上的错误是什么???谢谢,这确实有效。但我有一个问题。当它出现在地图上时。当设置为卫星时,它将关闭,您必须缩小一次才能看到位置。你能设定变焦吗?另一种方法是使用此方法设置标记。或者你必须在你的应用程序中构建一个地图来做类似的事情吗?Uri.parse(“geo:,?q=,(Label+Store10)”);我无法加载Uri,我认为这应该适合我。希望它在loc上放置一个标记。因为我的一些loc在购物中心。如果你知道在loc上放置标记的方法,请让我知道。。。
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(
"geo:"    + marker.getPosition().latitude +
","       + marker.getPosition().longitude +
"?q="     + marker.getPosition().latitude +
","       + marker.getPosition().longitude +                                   
"("       + marker.getTitle() + ")"));

intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);