1

I'm trying to get the name of a location from given latitude and longitude. Is there any possibility to get it like

getNameOfLocation(longitude,latitude)?

For example getNameOfLocation(48.1471904942317, 11.591434478759765) --> results Munich

I don't want to use any graphical elements to show like Google Maps.

Any ideas? Thanks for help

var geo = Ext.create('Ext.util.Geolocation', {
    autoUpdate: false,
    listeners: {
        locationupdate: function(geo) {
            alert('New latitude: ' + geo.getLatitude());
        },
        locationerror: function(geo, bTimeout, bPermissionDenied, bLocationUnavailable, message) {
            if(bTimeout){
                alert('Timeout occurred.');
            } else {
                alert('Error occurred.');
            }
        }
    }
});

geo.updateLocation();
Machavity
  • 30,841
  • 27
  • 92
  • 100
mediii
  • 97
  • 2
  • 12

2 Answers2

0

You can send an Ajax request to google maps API. For Example:

http://maps.googleapis.com/maps/api/geocode/json?latlng=48.1471904942317,11.591434478759765&sensor=false

and then parse the JSON result.

Darin Kolev
  • 3,401
  • 13
  • 31
  • 46
  • is that also possible with an native app? not a browser based web app – mediii Jul 06 '13 at 16:57
  • What do you mean with native app? You are using ExtJS, right? – Darin Kolev Jul 06 '13 at 17:00
  • my app isn't web based. It runs local on my android device like any native app from play store.. I use Sencha Touch and package it for my device Until now i didn't need JSON/Ajax etc. is there a possibility without? – mediii Jul 06 '13 at 17:03
  • if your app is developed with sencha touch - it is web based and if you have internet connection, you can make ajax requests. Without a request, you cannot retrieve the information about the location. – Darin Kolev Jul 06 '13 at 17:08
0

try this..

function getNameOfLocation(lat, lng) {
    var geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(lat, lng);
    geocoder.geocode({
        'latLng': latlng
    }, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            if (results[1]) {
alert(results[0].formatted_address) // your result              
 //country name
                for (var i=0; i<results[0].address_components.length; i++) {
                    for (var b=0;b<results[0].address_components[i].types.length;b++) {

                        if (results[0].address_components[i].types[b] == "administrative_area_level_1") {
                            city= results[0].address_components[i];
                            break;
                        }
                    }
                }


            } else {
                alert("No result");
            }
        } else {
            alert("failed: " + status);
        }
    });
}
Shashank Shukla
  • 1,146
  • 1
  • 17
  • 23
  • I need an API-key for that? – mediii Jul 07 '13 at 17:49
  • yes for google api you have a api key... first of all go to https://code.google.com/apis/console click on Services and slide on Google Maps API v3 than go to api access and create your app to generate your api key. – Shashank Shukla Jul 08 '13 at 06:34
  • for that you don't need an APi Key, there's a possibility without it: http://stackoverflow.com/a/12615275/2436861 – mediii Jul 08 '13 at 08:44