我已经有一个星期了。我尝试在我的应用中设置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);
}
});
}
}
这是我正在尝试设置的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);
}
});
答案 0 :(得分:4)
你可以尝试这些代码......
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);
答案 1 :(得分:3)
更改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);
如果您不想要标签,可以省略(标签+名称),它会根据最近的街道或其认为相关的其他东西随机选择一个。
答案 2 :(得分:3)
这就是我做到的......
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);
答案 3 :(得分:2)
// ---显示地图按钮---
b3 = (Button) findViewById(R.id.btn_showMap);
b3.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0){
Intent i = new
Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("geo:37.827500,-122.481670"));
startActivity(i);
}
});
答案 4 :(得分:1)
请检查here此网址可能对您有所帮助..
Uri uri = Uri.parse("geo:13.070984,80.253639");
Intent in = new Intent(Intent.ACTION_VIEW, uri);
startActivity(in);