Search code examples
androidapititaniummaps

titanium making maps in my app to locate some places. Giveing a lot of errors


I'm making an app and i need google maps inside it. It needs to highlight some spots and i found this code:

var MapModule = require('ti.map');
var win = Titanium.UI.createWindow();
var mountainView = MapModule.createAnnotation({
    latitude:37.390749,
    longitude:-122.081651,
    title:"Appcelerator Headquarters",
    subtitle:'Mountain View, CA',
    pincolor:MapModule.ANNOTATION_RED
});
var mapview = MapModule.createView({
    mapType: MapModule.NORMAL_TYPE,
    region: {latitude:33.74511, longitude:-84.38993,
            latitudeDelta:0.01, longitudeDelta:0.01},
    animate:true,
    regionFit:true,
    userLocation:true,
    annotations:[mountainView]
});
win.add(mapview);
win.open();

but it is giving me a lot of errors:

http://pastebin.com/kDwAsZWh

i have added the api key, also added ti.map to my TiApp. Can anyone help me out? :/

Thanks in advance!!!


Solution

  • Where are you try this code? Your problem is Google Play Services.

    You need an emulator or device with this services installed.

    At AVD Manager, you must use Targets with Google APIs prefix, for example (emulator 4.4.2):

    Google APIs (x86 System Image)(Google Inc.) - API Level 19.

    Also, at tiapp.xml you need add this permissions with your API key:

    <manifest android:versionName="1.0.0">
    ...
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-permission android:name="YOUR_APP_ID.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
    <uses-feature android:glEsVersion="0x00020000" android:required="true"/>
    <application>
       <meta-data android:name="com.google.android.gms.version" android:value="4452000"/>
       <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="YOUR_API_KEY"/>
    </application>
    ...
    </manifest>
    

    In theory, any phisical device can use Google Maps.