如何显示在Android的编程方式上内置的地图路线路线、方式、地图、Android

2023-09-07 13:31:41 作者:Animai°情兽

在全天的开支,我发现这个问题的解决方案:

After Full day Spending, I Found solution of this Question:

如何显示路线的内置的地图从一个当前位置到另一个地方使用经度/纬度或使用地址

五月是有帮助的你。

推荐答案

创建按钮布局文件:

layout.xml

<Button
    android:id="@+id/showMap"
    android:layout_width="@dimen/visit_button_width"
    android:layout_height="wrap_content"
    android:layout_marginTop="25dp"
    android:background="@drawable/login_button_selector"
    android:text="@string/title_show_map"
    android:textColor="@color/white"
    android:textSize="@dimen/button_text_size" />

的onClick 按钮的事件:

    ((Button)findViewById(R.id.showMap)).setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        /* Check Internet Connection */
        if(InternetConnection.checkConnection(context))
        {
            /** PROCESS for Get Longitude and Latitude **/
            locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

            // getting GPS status
            isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
            Log.d("msg", "GPS:"+isGPSEnabled);

            // check if GPS enabled     
            if(isGPSEnabled){
                Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

                if(location != null)
                {
                    longitude = String.valueOf(location.getLongitude());
                    latitude = String.valueOf(location.getLatitude());
                }

                //Add your Full Address Here
                String fullAddress = pref.getString("fulladdress", ""); 
                Log.d("msg", ""+fullAddress);

                Intent intent = new Intent(Intent.ACTION_VIEW, 
                        Uri.parse("http://maps.google.com/maps?f=d&daddr="+fullAddress));
                intent.setComponent(new ComponentName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"));
                startActivity(intent);

            }else{
                showAlertforGPS();
            }
        }else
        {
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(VisitAcitivity.this);

            // Setting Dialog Title
            alertDialog.setTitle("Internet Settings");

            // Setting Dialog Message
            alertDialog.setMessage("Internet Connection Not Available, Do you want to Connect?");

            // On pressing Settings button
            alertDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,int which) {
                    startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
                }
            });

            // on pressing cancel button
            alertDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });

            // Showing Alert Message
            alertDialog.show();
        }
    }
});

在的Andr​​oidManifest.xml 把这个权限:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

您可以问任何问题...

You can ask if Any Question...

 
精彩推荐
图片推荐