Monday, May 5, 2014

Android Map app tutorial

Below is where I will be providing all the code you will need.

This is everything that goes inside the Android tag-->

 <android xmlns:android="http://schemas.android.com/apk/res/android">
            <manifest>
            <uses-permission android:name="android.permission.INTERNET"/>
            <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

            <!-- Allows the API to cache data -->

            <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>  
            <!-- Use GPS for device location -->
           
            <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
            <!-- Use Wi-Fi or mobile connection for device location -->
           
            <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
            <!-- Allows the API to access Google web-based services -->

            <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
            <!-- Specify OpenGL ES 2.0 as a requirement -->
           
            <uses-feature android:glEsVersion="0x00020000" android:required="true"/>
            <!-- Replace <com.domain.appid> with your application ID -->

            <uses-permission android:name="com.domain.appid.permission.MAPS_RECEIVE"/>
            <permission android:name="com.domain.appid.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
            <application>
                <!-- Replace "place API key here" with the Google API key you obtained -->
    
                <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="place API key here"/>
           
            </application>
            
    </manifest>
            </android>

apps.js-->

// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');

// create tab group
var tabGroup = Titanium.UI.createTabGroup();

// create base UI tab and root window
var win1 = Titanium.UI.createWindow({ 
    title:'Tab 1',
    backgroundColor:'#fff',
    url: '"place file name that has the code for the map(ex:map.js)"'
});
var tab1 = Titanium.UI.createTab({ 
    icon:'KS_nav_views.png',
    title:'map',
    window:win1
});

//  add tabs
tabGroup.addTab(tab1); 

// open tab group
tabGroup.open();

map.js-->

var win = Titanium.UI.currentWindow;

var Map = require('ti.map');

var mountainView = Map.createAnnotation({
    latitude: enter latitude here,
    longitude: enter longitude here,
    title:"enter title of location here",
    subtitle: 'Ewing, NJ',
    pincolor: Map.ANNOTATION_RED,
    myid:1 // Custom property to uniquely identify this annotation.
});

var mapview = Map.createView({
    mapType: Map.SATELLITE_TYPE,
    animate:true,
    regionFit:true,
    userLocation:true,
    annotations:[mountainView]
});

win.add(mapview);

// Handle click events on any annotations on this map.
mapview.addEventListener('click', function(evt)
{
    Ti.API.info("Annotation " + evt.title + " clicked, id: " + evt.annotation.myid);
});

// set the distance filter
Titanium.Geolocation.distanceFilter = 10;
Ti.Geolocation.purpose = "To obtain user location.";

Titanium.Geolocation.getCurrentPosition(function(e)
{
            if (e.error)
            {
                        //if mapping location doesn't work, show an alert
                        alert('Sorry, but it seems geo location is not available on your device!');
                        return;
            }
           
            // get the properties from Titanium.GeoLocation
            var longitude = e.coords.longitude;
            var latitude = e.coords.latitude;
            var altitude = e.coords.altitude;
            var heading = e.coords.heading;
            var accuracy = e.coords.accuracy;
            var speed = e.coords.speed;
            var timestamp = e.coords.timestamp;
            var altitudeAccuracy = e.coords.altitudeAccuracy;
           
            //apply the lat and lon properties to our mapview
            mapview.region =
            {
                        latitude: latitude,
                        longitude: longitude,
                        latitudeDelta:0.5,
                        longitudeDelta:0.5
            };
});


Terminal input-->
Titanium Studios

keytool -list -v -keystore ~/Library/Application\ Support/Titanium/mobilesdk/osx/3.2.2.GA/android/dev_keystore

you will need to change the version accordingly to what version of titanium studies you are using. 

Android Studios
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android