如何验证谷歌地方AutoCompleteTextView

时间:2016-02-19 14:15:19

标签: android autocompletetextview google-places

我认为对某些人来说这可能是愚蠢的问题,但我不知道为什么我没有得到它。我的问题是,我通过google places api

得到经纬度

代码:

Geocoder geoCoder new Geocoder(this);
AutoCompleteTextView fAPSearchLocationEt;


        fAPSearchLocationLayout.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {


            try {

                List<Address> returnedaddresses = geoCoder.getFromLocationName(fAPSearchLocationEt.getText().toString(),1);

                if(returnedaddresses != null){

                    String latForVol = String.valueOf(returnedaddresses.get(0).getLatitude());
                    String longForVol = String.valueOf(returnedaddresses.get(0).getLongitude());

                    Log.e("Lat", latForVol);
                    Log.e("Long", longForVol);

                }else {
                    Log.e("Long", "Please give the correct address");
                }

            } catch (IOException e) {
                e.printStackTrace();
            }



        }
    });

所以,现在我要验证AutoCompleteTextView

验证说明:

假设用户提供了错误的地址,例如sadgdfhsfagAGDSFJDGHMSFSDFGsdfhg或其他任何地址。所以,在这种情况下,我想在setOnClickListener时验证正确的地址。

2 个答案:

答案 0 :(得分:0)

Google商家信息将自动执行此任务。如果你要验证&#34; sadgdfhsfagAGDSFJDGHMSFSDFGsdfhg&#34;那么你需要实现很多逻辑。

只需使用&#34; ResultCallback&#34;在代码中: -

                            <?php

                                if(isset($_POST['sendmail']) && isset($_FILES['file']) )
                                {
                                    $message = '<html><body>';
                                    $message .= '<img src="http://jehucocloud.co.za/chamber/chamber/profile_img/fnb.png" alt="Website Change Request" />';
                                    $message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
                                    $message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . $organisation . "</td></tr>";
                                    $message .= "<tr><td><strong>Email:</strong> </td><td>" . $organisationemail . "</td></tr>";
                                    $message .= "<tr><td><strong>Subject:</strong> </td><td>" . $subject . "</td></tr>";
                                    $message .= "<tr><td><strong>Our Website (main):</strong> </td><td><a href='". $organisationwebsite ."'>" . $organisationwebsite . "</a></td></tr>";
                                    $message .= "<tr><td><strong>Message:</strong> </td><td>" . $text_message . "</td></tr>";
                                    $message .= "</table>";
                                    $message .= "</body></html>";

                                    $attachments = $_FILES['file'];

                                    if(!empty($_POST['check_list'])){
                                         foreach($_POST['check_list'] as $report_id){
                                            if($report_id != null)
                                            {
                                                $recipient_email .= ','.$report_id;
                                                $recipient_email[0] = '';
                                            }
                                        }
                                     }

                                    if($recipient_email != null)
                                    {
                                        $file_count = count($attachments['name']); //count total files attached
                                        $boundary = md5("sanwebe.com");

                                        if($file_count > 0){

                                                 //header
                                                $headers = "MIME-Version: 1.0\r\n"; 
                                                $headers .= "From:".$from_email."\r\n"; 
                                                $headers .= "Reply-To: ".$recipient_email."" . "\r\n";
                                                $headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n"; 

                                                //message text
                                                $body = "--$boundary\r\n";
                                                $body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
                                                $body .= "Content-Transfer-Encoding: base64\r\n\r\n"; 
                                                $body .= chunk_split(base64_encode($message));


                                                 //attachments
                                                for ($x = 0; $x < $file_count; $x++){       
                                                    if(!empty($attachments['name'][$x])){

                                                        if($attachments['error'][$x]>0) //exit script and output error if we encounter any
                                                        {
                                                            $mymsg = array( 
                                                            1=>"The uploaded file exceeds the upload_max_filesize directive in php.ini", 
                                                            2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form", 
                                                            3=>"The uploaded file was only partially uploaded", 
                                                            4=>"No file was uploaded", 
                                                            6=>"Missing a temporary folder" ); 
                                                            die($mymsg[$attachments['error'][$x]]); 
                                                        }

                                                        //get file info
                                                        $file_name = $attachments['name'][$x];
                                                        $file_size = $attachments['size'][$x];
                                                        $file_type = $attachments['type'][$x];

                                                        //read file 
                                                        $handle = fopen($attachments['tmp_name'][$x], "r");
                                                        $content = fread($handle, $file_size);
                                                        fclose($handle);
                                                        $encoded_content = chunk_split(base64_encode($content)); //split into smaller chunks (RFC 2045)

                                                        $body .= "--$boundary\r\n";
                                                        $body .="Content-Type: $file_type; name=\"$file_name\"\r\n";
                                                        $body .="Content-Disposition: attachment; filename=\"$file_name\"\r\n";
                                                        $body .="Content-Transfer-Encoding: base64\r\n";
                                                        $body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n"; 
                                                        $body .= $encoded_content; 
                                                    }
                                                }

                                                $sentMail = @mail($recipient_email, $subject, $body, $headers);

                                                if($sentMail) //output success or failure messages
                                                {       
                                                    ?>
                                                        <div class="alert alert-success">
                                                            <button data-dismiss="alert" class="close" type="button">×</button>
                                                            <strong>You send an Email to all the selected recipients!</strong>
                                                        </div>
                                                    <?php
                                                }else{
                                                    ?>
                                                        <div class="alert alert-error">
                                                            <button data-dismiss="alert" class="close" type="button">×</button>
                                                            <strong>Could not send mail!</strong>
                                                        </div>
                                                    <?php  
                                                }
                                        }
                                    }
                                    else
                                    {
                                        ?>
                                            <div class="alert alert-error">
                                                <button data-dismiss="alert" class="close" type="button">×</button>
                                                <strong>You haven't selected recipients! You have to select atleast one recipient.</strong>
                                            </div>
                                        <?php 
                                    }
                                }
                            ?>
                            <form enctype="multipart/form-data" method="POST" action="">
                                <fieldset>
                                    <div class="control-group">
                                        <label class="control-label" for="input01">Subject</label>
                                        <div class="controls">
                                            <input required type="text" class="span8" name="subject" value="<?php echo $subject; ?>"  id="input01">
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label class="control-label">Attachmnet</label>
                                        <div class="controls">
                                            <input class="input-file" required name="file[]" multiple type="file">
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label class="control-label">Message</label>
                                        <div class="controls">
                                            <textarea required class="span12" rows="10"  name="text_message" cols="10"><?php echo $text_message; ?></textarea>
                                        </div>
                                    </div>
                                    <div class="control-group">
                                         <div class="span12">
                                            <div class="nonboxy-widget">
                                              <div class="widget-head">
                                                <h5 class="pull-left"><i class="black-icons list_images"></i> Select Companies</h5>
                                            </div>

                                              <table class="data-tbl-striped table table-striped table-bordered">
                                                <thead>
                                                  <tr>
                                                    <th class="center"> <input name="checkbox" type="checkbox" value="" class="checkall-task">
                                                    </th>
                                                    <th> Logo </th>
                                                    <th> RegNo </th>
                                                    <th> Company </th>
                                                    <th class="center"> Type </th>
                                                    <th class="center"> Bank </th>
                                                    <th class="center"> Account Status </th>
                                                    <th class="center"> Action </th>
                                                  </tr>
                                                </thead>
                                                <tbody>
                                                <?php

                                                    $query = "SELECT u.status,c.username,c.reg_no,c.enterprise_name,c.enterprise_type,c.bank,c.logo,c.email FROM company_details c,users u WHERE c.username=u.username order by c.enterprise_name";
                                                    $subject_set = mysqli_query($connection,$query); 

                                                    while($row = mysqli_fetch_array($subject_set))
                                                    {
                                                        if($row['status'] == 1 && $row['email']!='')
                                                        {
                                                         echo '<tr>
                                                            <td class="center tr-task-check"><input name="check_list[]" type="checkbox" value="'.$row['email'].'"></td>
                                                            <td class="center"><span class="user-thumb"><img src="../../y/profiles/'.$row['logo'].'" width="100" height="100" alt="User"></span></td>
                                                            <td>'.$row['reg_no'].'</td>
                                                            <td>'.$row['enterprise_name'].'</td>
                                                            <td class="center">'.$row['enterprise_type'].'</td>
                                                            <td class="center">'.$row['bank'].'</td>
                                                            <td class="center"><span class="label label-success">Active</span></td>
                                                            <td><div class="btn-group pull-right">
                                                                <button data-toggle="dropdown" class="btn dropdown-toggle"><i class="icon-cog "></i><span class="caret"></span></button>
                                                                <ul class="dropdown-menu">
                                                                  <li><a href="/chamber/view_business/?reg='.$row["reg_no"].'"><i class="icon-file"></i> View Details</a></li>
                                                                </ul>
                                                              </div></td>
                                                          </tr>';
                                                        }
                                                        else
                                                        {
                                                            echo '<tr>
                                                            <td class="center tr-task-check"><input name="check_list[]" type="checkbox" value="'.$row['email'].'"></td>
                                                            <td class="center"><span class="user-thumb"><img src="../../y/profiles/'.$row['logo'].'" width="40" height="40" alt="User"></span></td>
                                                            <td>'.$row['reg_no'].'</td>
                                                            <td>'.$row['enterprise_name'].'</td>
                                                            <td class="center">'.$row['enterprise_type'].'</td>
                                                            <td class="center">'.$row['bank'].'</td>
                                                            <td class="center"><span class="label label-important">Expired</span></td>
                                                            <td><div class="btn-group pull-right">
                                                                <button data-toggle="dropdown" class="btn dropdown-toggle"><i class="icon-cog "></i><span class="caret"></span></button>
                                                                <ul class="dropdown-menu">
                                                                  <li><a href="/chamber/view_business/?reg='.$row["reg_no"].'"><i class="icon-file"></i> View Details</a></li>
                                                                </ul>
                                                              </div></td>
                                                          </tr>';
                                                        }
                                                    }
                                                ?>
                                                </tbody>
                                              </table>
                                            </div>
                                        </div>
                                    </div>
                                    <div>
                                        <button type="submit" name="sendmail" class="btn btn-info"><i class="icon-retweet icon-white"></i> Send</button>
                                    </div>
                                </fieldset>
                            </form>

答案 1 :(得分:0)

我是通过

得到的
try {
                    List<Address> returnedaddresses = geoCoder.getFromLocationName(fAPSearchLocationEt.getText().toString(),1);

                    if(!returnedaddresses.isEmpty()){

                        String latForVol = String.valueOf(returnedaddresses.get(0).getLatitude());
                        String longForVol = String.valueOf(returnedaddresses.get(0).getLongitude());

                        Log.e("Lat", latForVol);
                        Log.e("Long", longForVol);
                        Log.e("Location", fAPSearchLocationEt.getText().toString());

                    }else {
                        Log.e("Long", "Please give the correct address");
                    }

                } catch (IOException e) {
                    e.printStackTrace();
                }