-1

I have a hard-coded address for particular place but i want to calculate current location longitude and latitude (using jquery or python script). This is my Django view at the moment:

def maps(request):
    school = School.objects.get(id=1)
    dictte={'latitude':school.latitute,'longitude':school.longitude}
    print dictte
    print dictte.keys()
    print dictte['latitude'],'-----'
    school_latitute = float(dictte['latitude'])
    print school_latitute,'raj'
    print dictte['longitude'],'===='
    school_longtitude = float(dictte['longitude'])
    print school
    api_key="aa"
    gmaps = GoogleMaps(api_key)
    address = 'Veerannapalya,Bangalore,Karnataka, India - 560043'
    lat, lng = gmaps.address_to_latlng(address)
    print lat, lng

    if lat == school_latitute and lng == school_longtitude:

        schoo = {'Name of the school':school.name, 'address':school.address.address}
        strf= str(schoo)
        print strf

        return HttpResponse(simplejson.dumps(strf),content_type = 'application/json; charset=utf8')
    else:
        print 'nothing'    
    return render_to_response('staff.html',{'lat':lat,'lng':lng},context_instance=RequestContext(request))

As you can see, the address is currently hardcoded in the line:

address = 'Veerannapalya,Bangalore,Karnataka, India - 560043'

Then, from this, I obtain the latitude/longitude. What I'd like to do is rather obtain the current location of the user in the browser, and then use this latitude/longitude.

Cœur
  • 32,421
  • 21
  • 173
  • 232
rajkumar
  • 105
  • 1
  • 1
  • 8
  • 2
    You need to clarify your question a little bit more. I'm not sure what you're asking. All I see is code. – Pwnna May 04 '11 at 14:44

1 Answers1

2

You can use the W3 geolocation API to do this client-side in JavaScript.

navigator.geolocation.getCurrentPosition(
  function(pos){
    var lat = pos.coords.latitude;
    var long = pos.coords.longitude;
    // send coordinates to server, or display on map, if you wish
  },
  function(){
    /* Handler if location could not be found */
  }
);

It's not an official specification yet, but it does work on most PC browsers and some phone browsers. Here's a list of devices where it does work.

Community
  • 1
  • 1
Herman Schaaf
  • 39,417
  • 19
  • 92
  • 137