I can't get my map to update The Location Continuously. The Json object doesn't move across the map over time. I have no errors. Does JSON work with google maps? A while loop seems useless. It feels simple but I'm not sure how to do it. I couldn't find anything on this on site.
Let me Know what you see. By the way I'm tracking a moving satellite.
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
JSONParser jsonparser = new JSONParser();
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
}
class Retrievedata extends AsyncTask<Void, String, Void> {
@Override
protected Void doInBackground(Void... params) {
try {
jobj = jsonparser.makeHttpRequest("http://api.wheretheiss.at/v1/satellites/25544");
String lat = "latitude : " + jobj.getString("latitude");
String longit ="longitude : " + jobj.getString("longitude");
Double latt = Double.parseDouble(lat);
Double longitt = Double.parseDouble(longit);
// this will cause onProgressUpdate to be called with lat & long
LatLng sydney = new LatLng(latt, longitt);
publishProgress(lat,longit);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
// it's okay to sleep within the background thread
} catch (JSONException e) {
Log.e("RetrieveData", "parse error", e);
}
return null;
}
@Override
protected void onProgressUpdate(String... values) {
}
}
}
this is my Gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.celest.iss.whereistheiss"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
useLibrary 'org.apache.http.legacy'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.android.gms:play-services-appindexing:9.8.0'
compile 'com.google.android.gms:play-services:9.8.0'
testCompile 'junit:junit:4.12'
}