by nolovelust
13. December 2010 09:38
Below code uses google maps api with local proxy code to get country,city and local area of user. Fully functuional apart from multiple entries not being filtered in the result. I'll hopefully fix it too.
It only workd phones that support navigator.geolocation such as iPhone, webOs, Android, Nokia N900
Due to same origin policy I've had to use local proxy code to download location data from google (see below)
To run the code create an html file and paste below code on to it
<script src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
function find() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
}
else if ( window.google && google.gears ) {
var geo = google.gears.factory.create( 'beta.geolocation' );
geo.getCurrentPosition(success, error);
}
else {
$('#output').html('Not supported');
}
}
function success(position) {
var lat = position.coords.latitude;
var long = position.coords.longitude;
var pullurl = 'getLocationResponse.ashx?latlng=' + lat + ',' + long;
get(pullurl);
//$('#output').html(pullurl);
}
function error(msg) {
$('#output').html('failed to get coordinates');
}
function get(url) {
$.ajax({
type: "GET",
url: url,
dataType: "xml",
success: parseXml,
error: function (xhr, status, error) {
$('#output').html("An AJAX error occured: " + status + "\nError: " + error);
}
});
}
function parseXml(xml) {
$(xml).find("GeocodeResponse").each(function () {
if ($(this).find("status").text() == "OK") {
parseOkXml(xml)
}
else {
$('#output').html('response code was not OK');
}
});
}
function parseOkXml(xml) {
$(xml).find('type').each(function () { // find all "type" tag in XML
if ($(this).text() == 'administrative_area_level_1') { // in here $(this) is our "type" tag
add($(this).parent().find('long_name').text());
//return false;
}
if ($(this).text() == 'administrative_area_level_2') { // in here $(this) is our "type" tag
add($(this).parent().find('long_name').text());
//return false;
}
if ($(this).text() == 'administrative_area_level_3') { // in here $(this) is our "type" tag
add($(this).parent().find('long_name').text());
//return false;
}
});
}
function add(data)
{
$('#location').append('');
}
</script>
Proxy code to load maps data from google getLocationResponse.ashx
<%@ WebHandler Language="C#" Class="getLocationResponse" %>
using System;
using System.Web;
using System.Net;
using System.IO;
public class getLocationResponse : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/xml";
string latlng = context.Request.QueryString["latlng"];
string url = "http://maps.google.com/maps/api/geocode/xml?latlng=" + latlng + "&sensor=true";
WebRequest request = WebRequest.Create(url);
request.Timeout = 1000;
;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (Stream dataStream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(dataStream))
{
context.Response.Write(reader.ReadToEnd());
}
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
you now can request location info by calling find() JavaScript function from html
by nolovelust
13. July 2010 15:35
StudioiPhone is set of controls from ComponentOne enables you to design iPhone web sites simply using ASP.Net Controls. Sounds good but it costs $1,100.00 with support or $800.00 without support.
Don't get me wrong, controls looks amazing and demo site is amazing too. But you are not creating an iPhone app! It is simply a mobile web site designed for iPhone you could use jQuery and Css to achieve same thing! See Building iPhone Apps from O'REILLY

by nolovelust
4. July 2010 09:25
UPDATE: Get Sql Server compact Edition 4 CTP from here and tools from here
For a small project you usually want to use light weight database engine without any server installation. SQLite and .Net implementation of it System.Data.SQLite was perfect for light weight web projects. Now there is SQL Server Compact Edition 4 from Microsoft. Due to be released shortly it will have features such as...
"Works with Existing Data APIs
SQL CE works with existing .NET-based data APIs, and supports a SQL Server compatible query syntax. This means you can use existing data APIs like ADO.NET, as well as use higher-level ORMs like Entity Framework and NHibernate with SQL CE. Pretty much any existing data API that supports the ADO.NET provider model will work with it.
This enables you to use the same data programming skills and data APIs you know today.
No Database Installation Required
SQL CE does not require you to run a setup or install a database server in order to use it. You can now simply copy the SQL CE binaries into the \bin directory of your ASP.NET application, and then your web application can run and use it as a database engine. No setup or extra security permissions are required for it to run. You do not need to have an administrator account on the machine. It just works.
Applications you build can redistribute SQL CE as part of them. Just copy your web application onto any server and it will work.
Database Files are Stored on Disk
SQL CE stores databases as files on disk (within files with a .sdf file extension). You can store SQL CE database files within the \App_Data folder of your ASP.NET Web application - they do not need to be registered in order to use them within your application.
The SQL CE database engine then runs in-memory within your application. When your application shuts down the database is automatically unloaded."
It sounds really cool. Head to http://weblogs.asp.net/scottgu/archive/2010/06/30/new-embedded-database-support-with-asp-net.aspx for more info.