Announcement

Collapse
No announcement yet.

Coordinates in a form

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Coordinates in a form

    How to automatically populate user coordinates (Lattitude / Longtitude) to the FORM based on a user location ?

    Arthur
    -----------------------------------------
    Arthur Klisiewicz
    dATA POINT SOFTWARE
    www.datapointsoftware.com

  • #2
    Mmm this is something similar as the other question. I use the googlemap api for that.
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development
    www.scriptcase.eu / www.scriptcase.nl

    Comment


    • #3
      ok, so how you connect Google API with SC ?
      -----------------------------------------
      Arthur Klisiewicz
      dATA POINT SOFTWARE
      www.datapointsoftware.com

      Comment


      • #4
        The following code is old, it might be that the api has been changed a little (V2->V3), but all docs are on google, so I hope this helps you on the way.

        Code:
           $key = "";
           $uei=$row['user_extended_id'];
           $address = urlencode($row['user_postcode']);
           $url = "http://maps.google.com/maps/api/geocode/json?address=".$address."&sensor=false";
        
        
           $ch = curl_init();
        
           curl_setopt($ch, CURLOPT_URL, $url);
           curl_setopt($ch, CURLOPT_HEADER,0);
           curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
           curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
           curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        
           $data = curl_exec($ch);
           curl_close($ch);
        
           $geo_json = json_decode($data, true);
        
           if ($geo_json['status'] =='OK') {
        //     $precision = $geo_json['Placemark'][0]['AddressDetails']['Accuracy'];
             $latitude = $geo_json['results'][0]['geometry']['location']['lng'];
             $longitude = $geo_json['results'][0]['geometry']['location']['lat'];
          
             $sql = "update e107_user_extended set user_lo='$longitude', user_la='$latitude' where user_extended_id=$uei"; 
             if (!mysql_query($sql,$link)) {
                die('Error: ' . mysql_error());
             } 
            } else {
         //     echo "Error in geocoding! Http error ".substr($data,0,3);
            }
          }
        Albert Drent
        aducom software netherlands
        scriptcase partner, reseller, support and (turn-key) development
        www.scriptcase.eu / www.scriptcase.nl

        Comment


        • #5
          Well I'm not a PHP coder like yourself so parts of this code are not really clear to me.
          I was hoping this would be JS so I can understand it a bit more.
          How would you implement it ? In the events ? Do you have anything working at this moment ?

          Art
          -----------------------------------------
          Arthur Klisiewicz
          dATA POINT SOFTWARE
          www.datapointsoftware.com

          Comment

          Working...
          X