This app is display my current moving path on map.
If you run the app the app displays 3 button and 1 input text.
If you touched 'rec' button then app getting your location using GPS or Network every 3 second.
And app save in database that displays your moving path on map using polyline.
If you touched 'stop' button then app delete polyline and database.
This picture is normal state(you run the app)
This picture is touched 'rec'button
This picture is touched 'stop' button
1. Using Database
Adding MainActivity.java code for using database
MainActivity.java
- mapview.getSettings().setDatabasePath("/data/data/"+this.getPackageName()+"/databases/");
- mapview.getSettings().setDomStorageEnabled(true);
- mapview.getSettings().setDatabaseEnabled(true);
- mapview.getSettings().setAppCacheEnabled(true);
and need a javascrpit code
index.html
- function setdatabase(){
- getMylocation();
- var sumlatlnt=curLat+","+curLng;
- localStorage.setItem(keycnt,sumlatlnt);
- keycnt++;
- }
This code is record to database.
and if you reading value in database
You need a this code
"var temp=localStorage.getItem(key)"
and remove code is
"localStorage.removeItem(key)"
2. overlay using polyline
It's simple drawing polyline using google maps API
you just add this code to initialize
- var polyOptions = {
- strokeColor: '#000000',
- strokeOpacity: 1.0,
- strokeWeight: 3
- };
- poly = new google.maps.Polyline(polyOptions);
- poly.setMap(map);
- path = poly.getPath();
and adding event function "path.push(event.latLng);"
But I used another method.
- if(navigator.geolocation) {
- navigator.geolocation.getCurrentPosition(function(position) {
- curLat=position.coords.latitude;
- curLng=position.coords.longitude;
- var newpos = new google.maps.LatLng(curLat,curLng);
- map.setCenter(newpos);
- path.push(newpos);
- }, function() {
- handleNoGeolocation(true);
- });
- } else {
- handleNoGeolocation(false);
- }
"path.push(latLng)" is draw polyline on map.
And "path.clear()" is clear polyline on map.
No comments:
Post a Comment