Not able to get the location data from app inventor location sensor

661 views
Skip to first unread message

Scientistnobee

unread,
Jul 4, 2015, 3:38:40 PM7/4/15
to mitappinv...@googlegroups.com

Hi everyone,

It's my first question here.

I am making an app in app inventor that requires location of the user. However, sometimes location is shown as longitude=0, lattitude=0 and No address in avialble. I don't know why its working at some locations and not at all the locations.


Get Altitude in App Inventor


I have tried the suggestions given in the above link, but no use. Finally, I have decided to get the coordinates from the map. For that I have tried the instructions given in the below link.


How do I let the user choose a location in Google Maps and return the chosen point to my App Inventor application?

Here, although I got the API, I don't know where to insert that key. I also don't have any source from the HTML page mentioned by user Taifun.


I have tried a lot to find the answers for my question on location sensor. I found few suggestions in stackexchange, by the members of this group. So I trying to post my question, as I did not get any reply in stack exchange. Could any one please help me. I have posted the screen shots of two of my screens.

Many thanks in advance.




SteveJG

unread,
Jul 4, 2015, 4:02:12 PM7/4/15
to mitappinv...@googlegroups.com
None of the blocks show you using the LocationSensor.    Perhaps try to understand how the GPS works ...   http://appinventor.mit.edu/explore/ai2/location-sensor.html  

Altitude:  you have to capture that in the LocationChanged block.   Several of the tutorials below (and the one above) show how to use the LocationChanged block.

0,0   means that the GPS does not have a satellite fix.  Do you have your device's GPS turned on?
Sometimes, No Address is Available   means no address is available on Google's data base.  This happens frequently in some large cities, in the dessert, etc.   If you are testing in your living room, the GPS probably cannot get a satellite fix  or if you are in a canyon created by large buildings.

Taifun's blocks require you purchase the html/java file from him it seems.

Try these tutorials:


Scientistnobee

unread,
Jul 4, 2015, 4:19:37 PM7/4/15
to mitappinv...@googlegroups.com

Hi Steve,

Many thanks for your kind reply. Its my mistake. I have uploaded the same image twice. Please look at the above pic. I have implimented the basic building blocks to show the location. And I tested it. It is working at some places. What I want is, when it is not able to get the satelite fix, then I want to insert the coordinates from the google map directly.

For that I have to understand the following three threads from Taifun

http://stackoverflow.com/questions/29292395/getting-app-inventor-2-variable-values-in-an-html-javascript-file
https://puravidaapps.com/snippets.php#2webviewstring
http://stackoverflow.com/questions/17010598/how-do-i-let-the-user-choose-a-location-in-google-maps-and-return-the-chosen-poi?lq=1

I hope now I make my question clear. I will look into the tutorials you provided and comeback.

Thanks again Steve :)

 

Scientistnobee

unread,
Jul 5, 2015, 3:12:20 AM7/5/15
to mitappinv...@googlegroups.com
Hi Steve,

I have followed the link and got the screen showing the coordinates as described by Taifun here and here. Below is the HTML code I used. Now I have to make this work within my app, not as a separate app and also pass the coordinate information back to my app. 

Many thanks Steve and Taifun. I will update my progress here!


<!DOCTYPE html>
<html>
   
<head>
     
<meta charset="utf-8">
     
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
     
<style type="text/css">
     html
{ height: 100% }
     body
{ height: 100%; margin: 0; padding: 0 }
     
#map_canvas { height: 100% }
     
</style>

     
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?&sensor=true&language=en"></script>

     
<script type="text/javascript">
 
function initialize() {
   
var mapOptions = {
      center
: new google.maps.LatLng(-34.397, 150.644),
      zoom
: 8,
      mapTypeId
: google.maps.MapTypeId.ROADMAP
     
};
     map
= new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

   
// Add a listener for the click event
    google
.maps.event.addListener(map, 'click', showPosition);
 
}

 
function showPosition(event) {
   
// display a marker on the map
    marker
= new google.maps.Marker({
      position
: event.latLng,
      map
: map,
      icon
: "./marker.png"
   
});

   
// print the selected position to the page title
   
var position = event.latLng.lat().toFixed(6) + ", " + event.latLng.lng().toFixed(6);
    window
.document.title = position;
 
}
</script>
 
</head>
 
<body onload="initialize()">
   
<div id="map_canvas" style="width:100%; height:100%"></div>
 
</body>
</html>


Reply all
Reply to author
Forward
0 new messages