Skip to content

Instantly share code, notes, and snippets.

@egomez99
Created April 21, 2014 17:43
Show Gist options
  • Save egomez99/11150227 to your computer and use it in GitHub Desktop.
Save egomez99/11150227 to your computer and use it in GitHub Desktop.
Google APIs V3 and Google Maps V2 (TiModule 2.1.4)
var v2 = 'http://maps.googleapis.com/maps/geo?output=json&q=';
var v3 = 'https://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=';
var xhr = Titanium.Network.createHTTPClient();
var query = 'Sydney Australia'; // or whatever you want to forward geocode
xhr.open('GET', v3 + query);
xhr.onload = function() {
var json = JSON.parse(this.responseText);
Ti.API.info(json);
};
//xhr.send();
var MapModule = require('ti.map');
var win = Ti.UI.createWindow({
backgroundColor : "white",
layout: 'vertical'
});
var lat, lon;
Titanium.Geolocation.forwardGeocoder(query, function(e){
//var json = JSON.stringify(e.longitude);
lon = e.longitude;
lat = e.latitude;
Ti.API.info(lon + ' ' +lat);
});
var map = MapModule.createView({
//userLocation : true,
mapType : MapModule.NORMAL_TYPE,
animate : true,
region : {
latitude : -33.8548157,
longitude : 151.2164539,
latitudeDelta : 0.1,
longitudeDelta : 0.1
}, //Sydney
top : 0,
left : 0
});
Ti.API.info(map.region.longitude +" - "+map.region.latitude);
var view = Ti.UI.createView({
left : 0,
top : 0,
width : 300,
height : 400
});
view.add(map);
var button1 = Ti.UI.createButton({
top : 15,
title : "slide view out"
});
button1.addEventListener("click", function() {
var animation = Ti.UI.createAnimation({
left : 200,
duration : 500
});
view.animate(animation);
});
var button2 = Ti.UI.createButton({
top : 15,
title : "slide view in"
});
button2.addEventListener("click", function() {
var animation = Ti.UI.createAnimation({
left : 100,
duration : 500
});
view.animate(animation);
});
win.add(view);
win.add(button1);
win.add(button2);
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment