通过短信发送我当前的位置作为网址地图

时间:2014-05-06 11:36:32

标签: android google-maps smsmanager

我想要做的是通过短信将我当前的位置地图作为网址发送,这样用户可以打开我的位置,一旦他打开已经添加到短信的网址,但是当我尝试发送短信时我会看到是网址,但它显示为常规文本而不是AS URL !!

这是我的代码请告诉我我做错了什么:

public class MapLocation extends FragmentActivity {
            TextView text;
            // Google Map
            private GoogleMap googleMap;
    String smslocation=null;
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.map_location);


                 text=(TextView)findViewById(R.id.textView1);
                 Button startBtn = (Button) findViewById(R.id.click);
                    initilizeMap();
                  startBtn.setOnClickListener(new View.OnClickListener() {
                      public void onClick(View view) {
                      sendSMS();
                   }
                  });
            }



            protected void sendSMS() {
                          Log.i("Send SMS", "");

                          Intent smsIntent = new Intent(Intent.ACTION_VIEW);
                          smsIntent.setData(Uri.parse("smsto:"));
                          smsIntent.setType("vnd.android-dir/mms-sms");

    //                    smsIntent.putExtra("address"  , new String ("0123456789"));
                          smsIntent.putExtra("sms_body"  , "i am currently in "+smslocation);
                          try {
                             startActivity(smsIntent);
                             finish();
                             Log.i("Finished sending SMS...", "");
                          } catch (android.content.ActivityNotFoundException ex) {
                             Toast.makeText(MapLocation.this, 
                             "SMS faild, please try again later.", Toast.LENGTH_SHORT).show();
                          }
                       }

    //          try {
    //              // Loading map


    //      }

    //
    //      @Override
    //      protected void onResume() {
    //          super.onResume();
    //          initilizeMap();
    //      }

            /**
             * function to load map If map is not created it will create it for you
             * */
            private void initilizeMap() {
                if (googleMap == null) {
                    googleMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

                    // check if map is created successfully or not
                    if (googleMap !=null) {
                        setUpMap();

                    }
                }
            }

            private void setUpMap() {
                //enable my location
                googleMap.setMyLocationEnabled(true);
                //get location object
                LocationManager locationManager=(LocationManager)getSystemService(LOCATION_SERVICE);
                //to retrive provider
                Criteria criteria = new Criteria();

                String provider = locationManager.getBestProvider(criteria, true);
                //get current location

                Location mylocation=locationManager.getLastKnownLocation(provider);
                //set map type
                googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
                double latitude = mylocation.getLatitude();
                double longitude = mylocation.getLongitude();
                LatLng latlng=new LatLng(latitude,longitude);

                googleMap.moveCamera(CameraUpdateFactory.newLatLng(latlng));
                googleMap.animateCamera(CameraUpdateFactory.zoomTo(20));
                googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude,longitude))).setTitle("you are here!");
                Toast.makeText(MapLocation.this, latitude+" "+longitude, Toast.LENGTH_LONG).show();
                Geocoder geocoder;
                List<Address> addresses;
                geocoder = new Geocoder(this, Locale.getDefault());
                try {
                    addresses = geocoder.getFromLocation(latitude, longitude, 1);
                    String address = addresses.get(0).getAddressLine(0);
                    String city = addresses.get(0).getAddressLine(1);
                    String country = addresses.get(0).getAddressLine(2);
                    String cities=addresses.get(0).getAdminArea();
                    Log.e("address",addresses+"");
                    Log.e("address",address+"");
                    Log.e("city",cities+"");
                    Log.e("country",city+"");
                    text.setText("your current location is: "+city+""+","+cities+""+","+address+"");
                    String uri = "http://maps.google.com/maps?saddr=" + mylocation.getLatitude()+","+mylocation.getLongitude();

                    Uri path= Uri.parse(uri); 
                    smslocation=city+""+","+cities+""+","+address+"  "+"check my location at "+path;

                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }


            }


        }

1 个答案:

答案 0 :(得分:0)

使用

SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("phoneNo", null, "http://maps.google.com/?q="+lat+","+lng, null, null);

这可能会对你有所帮助