如何通过手机短信发送到谷歌地图的位置

如何通过手机短信发送到谷歌地图的位置

本文介绍了如何通过手机短信发送到谷歌地图的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么分配在 SMSManager 的文本字符串变量的LocationManager
我想送坐标为文字信息的短信。

私人的LocationManager流明;
            私人LocationListener的LocationListener的;

 流明=(的LocationManager)
            getSystemService(Context.LOCATION_SERVICE);        LocationListener的=新MyLocationListener();        lm.requestLocationUpdates(
                LocationManager.GPS_PROVIDER,
             0,
             0,
            LocationListener的);
        lm.requestLocationUpdates(            LocationManager.NETWORK_PROVIDER,
            0,
            0,
            LocationListener的);
btnSendSMS =(按钮)findViewById(R.id.btnSendSMS);
    btnSendSMS.setOnClickListener(新View.OnClickListener(){
        @覆盖
        公共无效的onClick(视图v){
            // TODO自动生成方法存根
            sendSMS(55565,COORDS);        }
    }); 私人无效sendSMS(字符串phoneNumber的,字符串消息){    SmsManager短信= SmsManager.getDefault();
    sms.sendTextMessage(phoneNumber的,空的消息,NULL,NULL);
    }


解决方案

这是我的code通过电子邮件和手机短信发送当前位置希望它能帮助:)
根据您的需要修改

 最后的LocationManager mlocManager =(的LocationManager)getSystemService(Context.LOCATION_SERVICE);    最后LocationListener的mlocListener =新MyLocationListener();    最终定位位置= mlocManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    updateWithNewLocation(位置);
    mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,mlocListener);
    MC = mapview.getController();
    mc.setZoom(18);
    MLO =新MyLocationOverlay(这一点,MapView类);
    。调用MapView.getOverlays()加(MLO);
    mapview.invalidate();
    }
    公共类MyLocationListener实现LocationListener的    {    公共无效onLocationChanged(最终定位位置)
    {
        updateWithNewLocation(位置);
    }
    公共无效onProviderDisabled(字符串提供商){
        // TODO自动生成方法存根    }    公共无效onProviderEnabled(字符串提供商){
        // TODO自动生成方法存根    }    公共无效onStatusChanged(字符串提供商,INT地位,捆绑演员){
        // TODO自动生成方法存根    }    }    私人无效updateWithNewLocation(最终定位位置)
    {
    图形页面=(图形页面)findViewById(R.id.map);
    串latLongString;
    TextView的myLocationText;
    myLocationText =(的TextView)findViewById(R.id.text);
    字符串addressString =没有找到地址;    如果(位置!= NULL)
    {
    最终双纬度= location.getLatitude();
    最终双LNG​​ = location.getLongitude();    latLongString =纬度:+纬度+\\ nLong:+ LNG;
    最终双纬度= location.getLatitude();
    最终双经度= location.getLongitude();
    最后地理codeR GC =新的地缘codeR(这一点,Locale.getDefault());    最终的GeoPoint myLocation =新的GeoPoint((INT)(LAT * 1000000),(INT)(LNG * 1000000));
    。mapview.getController()animateTo(myLocation);
    mapview.getController()setCenter(myLocation)。
    尝试
    {
    最终名单<地址>地址= gc.getFromLocation(纬度,经度,4);
    最后StringBuilder的SB =新的StringBuilder();
    如果(addresses.size()大于0)
    {
        最终的地址地址= addresses.get(0);
        的for(int i = 0; I< address.getMaxAddressLineIndex();我++)
        {
            。sb.append(address.getAddressLine(I))追加(\\ n);
        }
        。sb.append(address.getLocality())追加(\\ n);
        。sb.append(address.getPostal code())追加(\\ n);
        sb.append(address.getCountryName());
    }
    addressString = sb.toString();
    }
    赶上(最终IOException异常E)
    {
    }
    }
    其他
    {
    latLongString =没有发现地点;
    }
    myLocationText.setText(您当前的位置为:\\ n+
    latLongString +\\ n+ addressString);
    }    @覆盖
        公共布尔onCreateOptionsMenu(菜单菜单){
            // TODO自动生成方法存根
        MenuInflater INF = getMenuInflater();
        inf.inflate(R.menu.newmenu,菜单);
            返回true;
    }    @覆盖
    公共布尔onOptionsItemSelected(菜单项项){
        串TV1;
        TextView的myLocationText;
        myLocationText =(的TextView)findViewById(R.id.text);
        TV1 = myLocationText.getText()的toString()。
    开关(item.getItemId()){
    案例R.id.msg:        意图sendIntent =新意图(Intent.ACTION_VIEW);
        sendIntent.putExtra(SMS_BODYTV1);
        sendIntent.setType(vnd.android-DI​​R / MMS短信);
        startActivity(sendIntent);    返回(真);
    案例R.id.email:
        / *创建意图* /
        最终意图emailIntent =新意图(android.content.Intent.ACTION_SEND);        / *填充数据* /
        emailIntent.setType(纯/文);
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,新的String [] {[email protected]});
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,主题);
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,TV1);
        startActivity(Intent.createChooser(emailIntent,发送邮件...));
         返回(真);
    }
    回报(super.onOptionsItemSelected(项目));
    }

how do I assign a variable LocationManager in the text string of SMSManager?I want to send the sms with coordinates as text message.

private LocationManager lm; private LocationListener locationListener;

    lm = (LocationManager)
            getSystemService(Context.LOCATION_SERVICE);

        locationListener = new MyLocationListener();

        lm.requestLocationUpdates(
                LocationManager.GPS_PROVIDER,
             0,
             0,
            locationListener);
        lm.requestLocationUpdates(

            LocationManager.NETWORK_PROVIDER,
            0,
            0,
            locationListener);


btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
    btnSendSMS.setOnClickListener(new View.OnClickListener() {


        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            sendSMS("55565", "coords" );

        }
    });



 private void sendSMS(String phoneNumber, String message) {

    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(phoneNumber, null, message, null, null);
    }
解决方案

This Was my code to send current location through email and sms Hope it helps :)modify it according to your need

final LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

    final LocationListener mlocListener = new MyLocationListener();

    final Location location = mlocManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    updateWithNewLocation(location);
    mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
    mc=mapview.getController();
    mc.setZoom(18);
    mlo=new MyLocationOverlay(this,mapview);
    mapview.getOverlays().add(mlo);
    mapview.invalidate();
    }




    public class MyLocationListener implements LocationListener

    {

    public void onLocationChanged(final Location location)
    {
        updateWithNewLocation(location);
    }
    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub

    }

    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }

    }

    private void updateWithNewLocation(final Location location)
    {
    mapview=(MapView) findViewById(R.id.map);
    String latLongString;
    TextView myLocationText;
    myLocationText = (TextView)findViewById(R.id.text);
    String addressString = "No address found";

    if ( location != null )
    {
    final double lat = location.getLatitude();
    final double lng = location.getLongitude();

    latLongString = "Lat:" + lat + "\nLong:" + lng;
    final double latitude = location.getLatitude();
    final double longitude = location.getLongitude();
    final Geocoder gc = new Geocoder(this, Locale.getDefault());

    final GeoPoint myLocation = new GeoPoint((int)(lat * 1000000), (int)(lng * 1000000));
    mapview.getController().animateTo(myLocation);
    mapview.getController().setCenter(myLocation);


    try
    {
    final List<Address> addresses = gc.getFromLocation(latitude, longitude, 4);
    final StringBuilder sb = new StringBuilder();
    if ( addresses.size() > 0 )
    {
        final Address address = addresses.get(0);
        for ( int i = 0; i < address.getMaxAddressLineIndex(); i++ )
        {
            sb.append(address.getAddressLine(i)).append("\n");
        }
        sb.append(address.getLocality()).append("\n");
        sb.append(address.getPostalCode()).append("\n");
        sb.append(address.getCountryName());
    }
    addressString = sb.toString();
    }
    catch ( final IOException e )
    {
    }
    }
    else
    {
    latLongString = "No location found";
    }
    myLocationText.setText("Your Current Position is:\n" +
    latLongString + "\n" + addressString);


    }





    @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // TODO Auto-generated method stub
        MenuInflater inf = getMenuInflater();
        inf.inflate(R.menu.newmenu, menu);
            return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        String tv1;
        TextView myLocationText;
        myLocationText = (TextView)findViewById(R.id.text);
        tv1= myLocationText.getText().toString();
    switch (item.getItemId()) {
    case R.id.msg:

        Intent sendIntent = new Intent(Intent.ACTION_VIEW);
        sendIntent.putExtra("sms_body", tv1);
        sendIntent.setType("vnd.android-dir/mms-sms");
        startActivity(sendIntent);

    return(true);
    case R.id.email:
        /* Create the Intent */
        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

        /* Fill it with Data */
        emailIntent.setType("plain/text");
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, tv1);
        startActivity(Intent.createChooser(emailIntent, "Send mail..."));
         return(true);
    }
    return(super.onOptionsItemSelected(item));
    }

这篇关于如何通过手机短信发送到谷歌地图的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 14:35