Identifying Mobiles Location

Is there a specific routine I can write into my code (that is running this application naturally via their mobile devices browser), that would identify the mobile devices exact location (address or long/lat) preferably based upon the GPS Sat (if not available communication network or Wi-Fi)?

Hi Larryh1115, read this:
http://stackoverflow.com/questions/12128990/does-gps-require-internet

Here is the solution, suitable for SC8 works with Ajax call on the second file written in PHP
Are Two Blank in SC8:

In the first Blank enter this code:

$Html_Geo = "
<html>
<head>
<meta http-equiv=‘content-type’ content=‘text/html; charset=windows-1250’>
</head>
<body>
<div id=‘geo’ class=‘geolocation_data’></div>
<script type=‘text/JavaScript’>
function GEOprocess(position) {
document.getElementById(‘geo’).innerHTML = ‘’;
//window.location.href = ‘".$perc_file_geo_php."?accuracy=’ + position.coords.accuracy + ‘&file_temp=".$perc_file_tmp."’ + ‘&latlng=’ + //position.coords.latitude + ‘,’ + position.coords.longitude +’&altitude=’+position.coords.altitude+’&altitude_accuracy=’+position.coords.altitudeAccuracy+’&//heading=’+position.coords.heading+’&speed=’+position.coords.speed+’’;
GEOajax(’".$perc_file_geo_php."?accuracy=’ + position.coords.accuracy +’&file_temp=".$perc_file_tmp."’ + ‘&latlng=’ + position.coords.latitude + ‘,’ +position.coords.longitude +’&altitude=’+position.coords.altitude+’&altitude_accuracy=’+position.coords.altitudeAccuracy+’&heading=’+position.coords.heading+’&speed=’+position.coords.speed+’’);
}
function GEOdeclined(error) {
document.getElementById(‘geo’).innerHTML = 'Error: ’ + error.message;
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(GEOprocess, GEOdeclined);
}else{
document.getElementById(‘geo’).innerHTML = ‘Your browser sucks. Upgrade it.’;
}
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}else if(window.ActiveXObject){
xmlHttp = new ActiveXObject(‘Microsoft.XMLHTTP’);
}
function GEOajax(url) {
xmlHttp.open(‘GET’, url, true);
xmlHttp.onreadystatechange = updatePage;
xmlHttp.send(null);
}
function updatePage() {
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
document.getElementById(‘geo’).innerHTML = ‘’ + response;
}
}
</script>
</body>
</html>
";
echo $Html_Geo;

In the Second Blank enter this code:

$geo = ‘http://maps.google.com/maps/api/geocode/xml?latlng=’.htmlentities(htmlspecialchars(strip_tags($_GET[‘latlng’]))).’&sensor=true’;
$xml = simplexml_load_file($geo);
foreach($xml->result->address_component as $component){
if($component->type==‘street_address’){
$geodata[‘precise_address’] = $component->long_name;
}
if($component->type==‘natural_feature’){
$geodata[‘natural_feature’] = $component->long_name;
}
if($component->type==‘airport’){
$geodata[‘airport’] = $component->long_name;
}
if($component->type==‘park’){
$geodata[‘park’] = $component->long_name;
}
if($component->type==‘point_of_interest’){
$geodata[‘point_of_interest’] = $component->long_name;
}
if($component->type==‘premise’){
$geodata[‘named_location’] = $component->long_name;
}
if($component->type==‘street_number’){
$geodata[‘numero_civico’] = $component->long_name;
}
if($component->type==‘route’){
$geodata[‘via’] = $component->long_name;
}
if($component->type==‘locality’){
$geodata[‘citta’] = $component->long_name;
}
if($component->type==‘administrative_area_level_3’){
$geodata[‘district_region’] = $component->long_name;
}
if($component->type==‘neighborhood’){
$geodata[‘neighborhood’] = $component->long_name;
}
if($component->type==‘colloquial_area’){
$geodata[‘locally_known_as’] = $component->long_name;
}
if($component->type==‘administrative_area_level_2’){
$geodata[‘county_state’] = $component->long_name;
}
if($component->type==‘postal_code’){
$geodata[‘cap’] = $component->long_name;
}
if($component->type==‘country’){
$geodata[‘stato’] = $component->long_name;
}

if($component-&gt;type=='administrative_area_level_1'){
    $geodata['regione'] = $component-&gt;long_name;
}    

if($component-&gt;type=='administrative_area_level_2'){
    $geodata['Provincia'] = $component-&gt;short_name;
}        

}

list($lat,$long) = explode(’,’,htmlentities(htmlspecialchars(strip_tags($_GET[‘latlng’]))));
$geodata[‘latitudine’] = $lat;
$geodata[‘longitudine’] = $long;
$geodata[‘formatted_address’] = $xml->result->formatted_address;
$geodata[‘precisione’] = htmlentities(htmlspecialchars(strip_tags($_GET[‘accuracy’])));
$geodata[‘altitudine’] = htmlentities(htmlspecialchars(strip_tags($_GET[‘altitude’])));
$geodata[‘altitudine_precisione’] = htmlentities(htmlspecialchars(strip_tags($_GET[‘altitude_accuracy’])));
$geodata[‘directional_heading’] = htmlentities(htmlspecialchars(strip_tags($_GET[‘heading’])));
$geodata[‘speed’] = htmlentities(htmlspecialchars(strip_tags($_GET[‘speed’])));
$geodata[‘google_api_src’] = $geo;

foreach($xml->result->address_component as $component){
if($component->type==‘street_address’){
$geodata[‘precise_address’] = $component->long_name;
}
if($component->type==‘natural_feature’){
$geodata[‘natural_feature’] = $component->long_name;
}
if($component->type==‘airport’){
$geodata[‘airport’] = $component->long_name;
}
if($component->type==‘park’){
$geodata[‘park’] = $component->long_name;
}
if($component->type==‘point_of_interest’){
$geodata[‘point_of_interest’] = $component->long_name;
}
if($component->type==‘premise’){
$geodata[‘named_location’] = $component->long_name;
}
if($component->type==‘street_number’){
$geodata[‘house_number’] = $component->long_name;
}
if($component->type==‘route’){
$geodata[‘street’] = $component->long_name;
}
if($component->type==‘locality’){
$geodata[‘town_city’] = $component->long_name;
}
if($component->type==‘administrative_area_level_3’){
$geodata[‘district_region’] = $component->long_name;
}
if($component->type==‘neighborhood’){
$geodata[‘neighborhood’] = $component->long_name;
}
if($component->type==‘colloquial_area’){
$geodata[‘locally_known_as’] = $component->long_name;
}
if($component->type==‘administrative_area_level_2’){
$geodata[‘county_state’] = $component->long_name;
}
if($component->type==‘postal_code’){
$geodata[‘postcode’] = $component->long_name;
}
if($component->type==‘country’){
$geodata[‘country’] = $component->long_name;
}
}

// CSS for DESKTOP and MOBILE
$Html_Maps_Img = “”;
// DESKTOP Css
if ([DISPOSITIVO]==“Desktop”)
$Html_Maps_Img = "
<style>
indirizzo{
position: absolute;
top: 5.5%;
right: 24.5%;
color: #000000;
font-family: ‘Arial Black’, Gadget, sans-serif;
font-size: ".[GG_Maps_Mappa]."vw; /* o vh vw*/
font-style: italic;
padding: 1em;
text-shadow: 0px 1px 0px #999, 0px 2px 0px #888, 0px 3px 0px #777, 0px 4px 0px #666, 0px 5px 0px #555, 0px 6px 0px #444, 0px 7px 0px #333, 0px 8px 7px #001135;
}
.geo_img_position {
position: absolute;
bottom: 50.00%;
left: 46.5%;
width: 7%;
height: auto;
}
#masc-maps{
width: 100%;
height: 100%;
margin-top: 2.5%;
margin-left: auto;
margin-right: auto;
text-align: center;
}
.maps-image {
position: relative;
width: 50vw; /era auto /
height: 88vh;
object-fit: cover;
overflow: hidden;
}
</style>
";
// MOBILE Css
else {
$Html_Maps_Img = "
<style>
indirizzo{
position: absolute;
top: 0.0%;
right: 2.0%;
color: #000000;
font-family: ‘Arial Black’, Gadget, sans-serif;
font-size: ".[GG_Maps_Mappa]."vw; /
o vh vw
/
font-style: italic;
padding: 1em;
text-shadow: 0px 1px 0px #999, 0px 2px 0px #888, 0px 3px 0px #777, 0px 4px 0px #666, 0px 5px 0px #555, 0px 6px 0px #444, 0px 7px 0px #333, 0px 8px 7px #001135;
}
.geo_img_position {
position: absolute;
bottom: 50.00%;
left: 40.0%;
width: 20%;
height: auto;
}
#masc-maps{
width: 100%;
height: 100%;
margin-top: 0%;
margin-left: auto;
margin-right: auto;
text-align: center;
}
.maps-image {
position: relative;
width: 100%;
height: 95vh;
object-fit: cover;
overflow: hidden;
}
</style>
";

$Html_Maps_Img .= ‘<html>’;
$Html_Maps_Img .= ‘<body>’;
$Html_Maps_Img .= ‘<div id=“masc-maps” >’;
$Html_Maps_Img .= ‘<a href="…/Escort-Accompagnatrici-Italia-D-Gallery/index.php">’;
$Html_Maps_Img .= ‘<img src=“http://maps.google.com/maps/api/staticmap?center=’.$lat.’,’.$long.’&zoom=14&size=850x850&maptype=roadmap&&sensor=true” class=“maps-image” alt="’.$geodata[‘formatted_address’].’" /><br /><br />’;
$Html_Maps_Img .= ‘</a>’;
$Html_Maps_Img .= ‘%ICO_GEO_POSITION%’;
$Html_Maps_Img .= ‘%INDIRIZZO_COMPLETO%’;
$Html_Maps_Img .= ‘</div>’;
$Html_Maps_Img .= ‘</body>’;
$Html_Maps_Img .= ‘</html>’;

// Ico GEO POSITION
$tmp_ico_geo_position="<img class=‘geo_img_position’ src=’".[_PERC_wm_h].“Geo_Posizizione_128x128.png”."’ />";
$Html_Maps_Img=str_replace("%ICO_GEO_POSITION%",$tmp_ico_geo_position,$Html_Maps_Img);

// Indirizzo
$tmp_indirizzo="<indirizzo>".“Ti trovi nei pressi di:<br>”.$GEO_Indirizzo_Completo."</indirizzo>";
$Html_Maps_Img=str_replace("%INDIRIZZO_COMPLETO%",$tmp_indirizzo,$Html_Maps_Img);

echo $Html_Maps_Img;

Hello
The first Blank calls the second Blank using Ajax, the second Blank displays the map on the screen with the current position.
Attention in the second Blank there are two CSS for DeskTop and Mobile, I have managed the CSS switch with a variable.
Also calls for the (second Blank PHP file) i used as a filename variable.
I extracted the code from my APP complex and I pretty quickly tried to clean it, tell me if you have trouble, i can create two Blank that work independently of the rest of my code.

Wow, thank you so much. I will create x2 separate “blank” app’s. I will then make HTML_Geo
Have I missed anything?
Thanks so much
Larry

hello, you are right, you have not forgotten anything, the two Blank you must create inside of SC8.

Hi -

Couldn’t get it to run, kept getting error code 500 (even with debug on) [LIST=1]

  • Named the first app, "assetLocation1" and the 2nd "assetLocation2".
  • I then updated the first line of assetLocation1 to [I]$Html_Geo = 'assetLocation2'; [/I]
  • I then compiled both app's and tried to run assetLocation1, but got error code 500. [/LIST] Not sure what I am doing wrong or have missed.

    See below “assetLocation1”

    [I]$Html_Geo = ‘assetLocation2’;
    <html>
    <head>
    <meta http-equiv=‘content-type’ content=‘text/html; charset=windows-1250’>
    </head>
    <body>
    <div id=‘geo’ class=‘geolocation_data’></div>
    <script type=‘text/JavaScript’>

    function GEOprocess(position) {
    document.getElementById(‘geo’).innerHTML = ‘’;
    //window.location.href = ‘".$perc_file_geo_php."?accuracy=’ + position.coords.accuracy + ‘&file_temp=".$perc_file_tmp."’ + ‘&latlng=’ + //position.coords.latitude + ‘,’ + position.coords.longitude +’&altitude=’+position.coords.altitude+’&altitude_ accuracy=’+position.coords.altitudeAccuracy+’&//heading=’+position.coords.heading+’&speed=’+positi on.coords.speed+’’;
    GEOajax(’".$perc_file_geo_php."?accuracy=’ + position.coords.accuracy +’&file_temp=".$perc_file_tmp."’ + ‘&latlng=’ + position.coords.latitude + ‘,’ +position.coords.longitude +’&altitude=’+position.coords.altitude+’&altitude_ accuracy=’+position.coords.altitudeAccuracy+’&head ing=’+position.coords.heading+’&speed=’+position.c oords.speed+’’);
    }

    function GEOdeclined(error) {
    document.getElementById(‘geo’).innerHTML = 'Error: ’ + error.message;
    }
    if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(GEOproces s, GEOdeclined);
    }else{
    document.getElementById(‘geo’).innerHTML = ‘Your browser sucks. Upgrade it.’;
    }
    if (window.XMLHttpRequest) {
    xmlHttp = new XMLHttpRequest();
    }else if(window.ActiveXObject){
    xmlHttp = new ActiveXObject(‘Microsoft.XMLHTTP’);
    }

    function GEOajax(url) {
    xmlHttp.open(‘GET’, url, true);
    xmlHttp.onreadystatechange = updatePage;
    xmlHttp.send(null);
    }

    function updatePage() {
    if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    document.getElementById(‘geo’).innerHTML = ‘’ + response;
    }
    }[/I]

    Then below is an exact copy of assetLocation2 (no changes at all):

    [I]$geo = ‘http://maps.google.com/maps/api/geocode/xml?latlng=’.htmlentities(htmlspecialchars(strip_t ags($_GET[‘latlng’]))).’&sensor=true’;
    $xml = simplexml_load_file($geo);
    foreach($xml->result->address_component as $component){
    if($component->type==‘street_address’){
    $geodata[‘precise_address’] = $component->long_name;
    }
    if($component->type==‘natural_feature’){
    $geodata[‘natural_feature’] = $component->long_name;
    }
    if($component->type==‘airport’){
    $geodata[‘airport’] = $component->long_name;
    }
    if($component->type==‘park’){
    $geodata[‘park’] = $component->long_name;
    }
    if($component->type==‘point_of_interest’){
    $geodata[‘point_of_interest’] = $component->long_name;
    }
    if($component->type==‘premise’){
    $geodata[‘named_location’] = $component->long_name;
    }
    if($component->type==‘street_number’){
    $geodata[‘numero_civico’] = $component->long_name;
    }
    if($component->type==‘route’){
    $geodata[‘via’] = $component->long_name;
    }
    if($component->type==‘locality’){
    $geodata[‘citta’] = $component->long_name;
    }
    if($component->type==‘administrative_area_level_3’){
    $geodata[‘district_region’] = $component->long_name;
    }
    if($component->type==‘neighborhood’){
    $geodata[‘neighborhood’] = $component->long_name;
    }
    if($component->type==‘colloquial_area’){
    $geodata[‘locally_known_as’] = $component->long_name;
    }
    if($component->type==‘administrative_area_level_2’){
    $geodata[‘county_state’] = $component->long_name;
    }
    if($component->type==‘postal_code’){
    $geodata[‘cap’] = $component->long_name;
    }
    if($component->type==‘country’){
    $geodata[‘stato’] = $component->long_name;
    }

    if($component->type==‘administrative_area_level_1’){
    $geodata[‘regione’] = $component->long_name;
    }

    if($component->type==‘administrative_area_level_2’){
    $geodata[‘Provincia’] = $component->short_name;
    }
    }

    list($lat,$long) = explode(’,’,htmlentities(htmlspecialchars(strip_ta gs($_GET[‘latlng’]))));
    $geodata[‘latitudine’] = $lat;
    $geodata[‘longitudine’] = $long;
    $geodata[‘formatted_address’] = $xml->result->formatted_address;
    $geodata[‘precisione’] = htmlentities(htmlspecialchars(strip_tags($_GET[‘accuracy’])));
    $geodata[‘altitudine’] = htmlentities(htmlspecialchars(strip_tags($_GET[‘altitude’])));
    $geodata[‘altitudine_precisione’] = htmlentities(htmlspecialchars(strip_tags($_GET[‘altitude_accuracy’])));
    $geodata[‘directional_heading’] = htmlentities(htmlspecialchars(strip_tags($_GET[‘heading’])));
    $geodata[‘speed’] = htmlentities(htmlspecialchars(strip_tags($_GET[‘speed’])));
    $geodata[‘google_api_src’] = $geo;

    foreach($xml->result->address_component as $component){
    if($component->type==‘street_address’){
    $geodata[‘precise_address’] = $component->long_name;
    }
    if($component->type==‘natural_feature’){
    $geodata[‘natural_feature’] = $component->long_name;
    }
    if($component->type==‘airport’){
    $geodata[‘airport’] = $component->long_name;
    }
    if($component->type==‘park’){
    $geodata[‘park’] = $component->long_name;
    }
    if($component->type==‘point_of_interest’){
    $geodata[‘point_of_interest’] = $component->long_name;
    }
    if($component->type==‘premise’){
    $geodata[‘named_location’] = $component->long_name;
    }
    if($component->type==‘street_number’){
    $geodata[‘house_number’] = $component->long_name;
    }
    if($component->type==‘route’){
    $geodata[‘street’] = $component->long_name;
    }
    if($component->type==‘locality’){
    $geodata[‘town_city’] = $component->long_name;
    }
    if($component->type==‘administrative_area_level_3’){
    $geodata[‘district_region’] = $component->long_name;
    }
    if($component->type==‘neighborhood’){
    $geodata[‘neighborhood’] = $component->long_name;
    }
    if($component->type==‘colloquial_area’){
    $geodata[‘locally_known_as’] = $component->long_name;
    }
    if($component->type==‘administrative_area_level_2’){
    $geodata[‘county_state’] = $component->long_name;
    }
    if($component->type==‘postal_code’){
    $geodata[‘postcode’] = $component->long_name;
    }
    if($component->type==‘country’){
    $geodata[‘country’] = $component->long_name;
    }
    }

    // CSS for DESKTOP and MOBILE
    $Html_Maps_Img = “”;
    // DESKTOP Css
    if ([DISPOSITIVO]==“Desktop”)
    $Html_Maps_Img = ";
    <style>
    indirizzo{
    position: absolute;
    top: 5.5%;
    right: 24.5%;
    color: #000000;
    font-family: ‘Arial Black’, Gadget, sans-serif;
    font-size: ".[GG_Maps_Mappa]."vw; /* o vh vw*/
    font-style: italic;
    padding: 1em;
    text-shadow: 0px 1px 0px #999, 0px 2px 0px #888, 0px 3px 0px #777, 0px 4px 0px #666, 0px 5px 0px #555, 0px 6px 0px #444, 0px 7px 0px #333, 0px 8px 7px #001135;
    }
    .geo_img_position {
    position: absolute;
    bottom: 50.00%;
    left: 46.5%;
    width: 7%;
    height: auto;
    }
    #masc-maps{
    width: 100%;
    height: 100%;
    margin-top: 2.5%;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    }
    .maps-image {
    position: relative;
    width: 50vw; /era auto /
    height: 88vh;
    object-fit: cover;
    overflow: hidden;
    }
    </style>
    ";
    // MOBILE Css
    else {
    $Html_Maps_Img = ";
    <style>
    indirizzo{
    position: absolute;
    top: 0.0%;
    right: 2.0%;
    color: #000000;
    font-family: ‘Arial Black’, Gadget, sans-serif;
    font-size: ".[GG_Maps_Mappa]."vw; /
    o vh vw
    /
    font-style: italic;
    padding: 1em;
    text-shadow: 0px 1px 0px #999, 0px 2px 0px #888, 0px 3px 0px #777, 0px 4px 0px #666, 0px 5px 0px #555, 0px 6px 0px #444, 0px 7px 0px #333, 0px 8px 7px #001135;
    }
    .geo_img_position {
    position: absolute;
    bottom: 50.00%;
    left: 40.0%;
    width: 20%;
    height: auto;
    }
    #masc-maps{
    width: 100%;
    height: 100%;
    margin-top: 0%;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    }
    .maps-image {
    position: relative;
    width: 100%;
    height: 95vh;
    object-fit: cover;
    overflow: hidden;
    }
    </style>
    ";

    $Html_Maps_Img .= ‘<html>’;
    $Html_Maps_Img .= ‘<body>’;
    $Html_Maps_Img .= ‘<div id=“masc-maps” >’;
    $Html_Maps_Img .= ‘<a href="…/Escort-Accompagnatrici-Italia-D-Gallery/index.php">’;
    $Html_Maps_Img .= ‘<img src=“http://maps.google.com/maps/api/staticmap?center=’.$lat.’,’.$long.’&zoom=14&size=8 50x850&maptype=roadmap&&sensor=true” class=“maps-image” alt="’.$geodata[‘formatted_address’].’" /><br /><br />’;
    $Html_Maps_Img .= ‘</a>’;
    $Html_Maps_Img .= ‘%ICO_GEO_POSITION%’;
    $Html_Maps_Img .= ‘%INDIRIZZO_COMPLETO%’;
    $Html_Maps_Img .= ‘</div>’;
    $Html_Maps_Img .= ‘</body>’;
    $Html_Maps_Img .= ‘</html>’;

    // Ico GEO POSITION
    $tmp_ico_geo_position="<img class=‘geo_img_position’ src=’".[_PERC_wm_h].“Geo_Posizizione_128x128.png”."’ />";
    $Html_Maps_Img=str_replace("%ICO_GEO_POSITION%", $tmp_ico_geo_position,$Html_Maps_Img);

    // Indirizzo
    $tmp_indirizzo="<indirizzo>".“Ti trovi nei pressi di:<br>”.$GEO_Indirizzo_Completo."</indirizzo>";
    $Html_Maps_Img=str_replace("%INDIRIZZO_COMPLETO% ",$tmp_indirizzo,$Html_Maps_Img);

    echo $Html_Maps_Img;

    </script>
    </body>
    </html>
    ";
    echo $Html_Geo;[/I]

  • Hello Larry, here are the two files php cleaned and working independently,
    you just need to set the paths of the following variables:

    In Blank_Geo_1.php file:
    $ Perc_file_geo2_php = “…/Blank_Geo_2/index.php”; // The Position of Blank_Geo_2

    in Blank_Geo_2
    $ Ico_image_pointer = “…/image/Geo_Point 128x128.png”; // ICO/IMAGE Indicating your position on the map
    $ Device = “Desktop”; // For select correct CSS (may be Desktop or Mobile)

    Let me know if everything is OK.

    Geo2_php.zip (9.46 KB)

    Thank you so much it works. I realize I must post the icon to the image folder.
    One question.
    It says I am near “40”, not an address like you show in your image.
    What would or does that mean?
    [ATTACH=CONFIG]n65325[/ATTACH]

    Location.png

    It works, fantastic. THANK YOU!!!

    How do I force HIGH ACCURACY? Can’t see where to edit that?