Android Intent for google.maps onclick

时间:2012-09-01 01:30:45

标签: android

我从用户输入两个值,即经度和纬度,并且有一个显示位置按钮,单击时,它会使用这两个经度和纬度值显示位置。 我只需要在showlocation()或按钮

上使用intent

请检查我的代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:orientation="horizontal" >


 <EditText android:id="@+id/lat"
        android:layout_weight="50"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:hint="@string/lat" />

 <EditText
     android:id="@+id/longi"
     android:layout_width="0dp"
     android:layout_height="wrap_content"
     android:layout_weight="50"
     android:ems="10"
     android:hint="@string/longi" >

     <requestFocus />
 </EditText>

 <Button
     android:layout_width="1dp"
     android:layout_height="wrap_content"
     android:layout_weight="100"
     android:text="@string/button_send"
     android:onClick="showlocation()" />
</LinearLayout>



public void showlocation(){

        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 个答案:

答案 0 :(得分:0)

不太清楚你想要什么。

尝试将按钮上的onClick属性设置为showLocation,而不是showLocation()

之后,您需要在public

上创建Activity方法
public void showLocation(View v) {
    // do what you want if the button is clicked by user

}

或者您可以删除onClick上的button属性,将id属性添加到该按钮,以便您可以在Activity上找到该属性,然后让您{ {1}}

Activity implements onClickListener