Finding nearby cities using Google API











up vote
-1
down vote

favorite












I want to get nearby cities from passed latitude and longitude. I have used the geonames and geobytes APIs but want to use Google API for finding nearby cities.



This is my code:



def getNearbyCities(self):
# lat, lon = self.getLatLon()
# res_url = urlopen('http://gd.geobytes.com/GetNearbyCities?callback=?&radius=100&limit=100&Latitude=' + str(lat) + '&Longitude=' + str(lon))
res_url = urlopen('http://getnearbycities.geobytes.com/GetNearbyCities?callback=?&radius=100&locationcode=' + str(self.city))

resp = str(res_url.read())
print(resp)
validate_res = resp.split("b'?(")[-1].split(");'")[0]
validated_res = ast.literal_eval(validate_res)

cities_nd_distence =
for data in validated_res:
data_tuple = (data[1], data[7])
if data[1] not in cities_nd_distence:
cities_nd_distence.append(data_tuple)
import pprint
pprint.pprint(cities_nd_distence)
return cities_nd_distence









share|improve this question









New contributor




kulveer singh Mrar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Google doesn't provide that (at least not via the Maps API). Use another service or create your own data source.
    – MrUpsidown
    yesterday















up vote
-1
down vote

favorite












I want to get nearby cities from passed latitude and longitude. I have used the geonames and geobytes APIs but want to use Google API for finding nearby cities.



This is my code:



def getNearbyCities(self):
# lat, lon = self.getLatLon()
# res_url = urlopen('http://gd.geobytes.com/GetNearbyCities?callback=?&radius=100&limit=100&Latitude=' + str(lat) + '&Longitude=' + str(lon))
res_url = urlopen('http://getnearbycities.geobytes.com/GetNearbyCities?callback=?&radius=100&locationcode=' + str(self.city))

resp = str(res_url.read())
print(resp)
validate_res = resp.split("b'?(")[-1].split(");'")[0]
validated_res = ast.literal_eval(validate_res)

cities_nd_distence =
for data in validated_res:
data_tuple = (data[1], data[7])
if data[1] not in cities_nd_distence:
cities_nd_distence.append(data_tuple)
import pprint
pprint.pprint(cities_nd_distence)
return cities_nd_distence









share|improve this question









New contributor




kulveer singh Mrar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Google doesn't provide that (at least not via the Maps API). Use another service or create your own data source.
    – MrUpsidown
    yesterday













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I want to get nearby cities from passed latitude and longitude. I have used the geonames and geobytes APIs but want to use Google API for finding nearby cities.



This is my code:



def getNearbyCities(self):
# lat, lon = self.getLatLon()
# res_url = urlopen('http://gd.geobytes.com/GetNearbyCities?callback=?&radius=100&limit=100&Latitude=' + str(lat) + '&Longitude=' + str(lon))
res_url = urlopen('http://getnearbycities.geobytes.com/GetNearbyCities?callback=?&radius=100&locationcode=' + str(self.city))

resp = str(res_url.read())
print(resp)
validate_res = resp.split("b'?(")[-1].split(");'")[0]
validated_res = ast.literal_eval(validate_res)

cities_nd_distence =
for data in validated_res:
data_tuple = (data[1], data[7])
if data[1] not in cities_nd_distence:
cities_nd_distence.append(data_tuple)
import pprint
pprint.pprint(cities_nd_distence)
return cities_nd_distence









share|improve this question









New contributor




kulveer singh Mrar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I want to get nearby cities from passed latitude and longitude. I have used the geonames and geobytes APIs but want to use Google API for finding nearby cities.



This is my code:



def getNearbyCities(self):
# lat, lon = self.getLatLon()
# res_url = urlopen('http://gd.geobytes.com/GetNearbyCities?callback=?&radius=100&limit=100&Latitude=' + str(lat) + '&Longitude=' + str(lon))
res_url = urlopen('http://getnearbycities.geobytes.com/GetNearbyCities?callback=?&radius=100&locationcode=' + str(self.city))

resp = str(res_url.read())
print(resp)
validate_res = resp.split("b'?(")[-1].split(");'")[0]
validated_res = ast.literal_eval(validate_res)

cities_nd_distence =
for data in validated_res:
data_tuple = (data[1], data[7])
if data[1] not in cities_nd_distence:
cities_nd_distence.append(data_tuple)
import pprint
pprint.pprint(cities_nd_distence)
return cities_nd_distence






python google-maps-api-3 django-rest-framework google-places-api






share|improve this question









New contributor




kulveer singh Mrar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




kulveer singh Mrar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday









Mihai Chelaru

2,0177820




2,0177820






New contributor




kulveer singh Mrar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









kulveer singh Mrar

41




41




New contributor




kulveer singh Mrar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





kulveer singh Mrar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






kulveer singh Mrar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Google doesn't provide that (at least not via the Maps API). Use another service or create your own data source.
    – MrUpsidown
    yesterday


















  • Google doesn't provide that (at least not via the Maps API). Use another service or create your own data source.
    – MrUpsidown
    yesterday
















Google doesn't provide that (at least not via the Maps API). Use another service or create your own data source.
– MrUpsidown
yesterday




Google doesn't provide that (at least not via the Maps API). Use another service or create your own data source.
– MrUpsidown
yesterday












1 Answer
1






active

oldest

votes

















up vote
0
down vote













If you only want to get cities based on latitude and longitude, you can have a look at https://github.com/coderholic/django-cities



from cities.models import City                                                                                

from django.contrib.gis.geos import Point

from django.contrib.gis.db.models.functions import Distance

p = Point(-118, 34, srid=4326)

City.objects.annotate(distance=Distance('location', p)).order_by("distance").first()

<City: Hacienda Heights>


enter image description here






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });






    kulveer singh Mrar is a new contributor. Be nice, and check out our Code of Conduct.










     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372088%2ffinding-nearby-cities-using-google-api%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    If you only want to get cities based on latitude and longitude, you can have a look at https://github.com/coderholic/django-cities



    from cities.models import City                                                                                

    from django.contrib.gis.geos import Point

    from django.contrib.gis.db.models.functions import Distance

    p = Point(-118, 34, srid=4326)

    City.objects.annotate(distance=Distance('location', p)).order_by("distance").first()

    <City: Hacienda Heights>


    enter image description here






    share|improve this answer



























      up vote
      0
      down vote













      If you only want to get cities based on latitude and longitude, you can have a look at https://github.com/coderholic/django-cities



      from cities.models import City                                                                                

      from django.contrib.gis.geos import Point

      from django.contrib.gis.db.models.functions import Distance

      p = Point(-118, 34, srid=4326)

      City.objects.annotate(distance=Distance('location', p)).order_by("distance").first()

      <City: Hacienda Heights>


      enter image description here






      share|improve this answer

























        up vote
        0
        down vote










        up vote
        0
        down vote









        If you only want to get cities based on latitude and longitude, you can have a look at https://github.com/coderholic/django-cities



        from cities.models import City                                                                                

        from django.contrib.gis.geos import Point

        from django.contrib.gis.db.models.functions import Distance

        p = Point(-118, 34, srid=4326)

        City.objects.annotate(distance=Distance('location', p)).order_by("distance").first()

        <City: Hacienda Heights>


        enter image description here






        share|improve this answer














        If you only want to get cities based on latitude and longitude, you can have a look at https://github.com/coderholic/django-cities



        from cities.models import City                                                                                

        from django.contrib.gis.geos import Point

        from django.contrib.gis.db.models.functions import Distance

        p = Point(-118, 34, srid=4326)

        City.objects.annotate(distance=Distance('location', p)).order_by("distance").first()

        <City: Hacienda Heights>


        enter image description here







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited yesterday

























        answered yesterday









        Mohammad Umair

        1,7281520




        1,7281520






















            kulveer singh Mrar is a new contributor. Be nice, and check out our Code of Conduct.










             

            draft saved


            draft discarded


















            kulveer singh Mrar is a new contributor. Be nice, and check out our Code of Conduct.













            kulveer singh Mrar is a new contributor. Be nice, and check out our Code of Conduct.












            kulveer singh Mrar is a new contributor. Be nice, and check out our Code of Conduct.















             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372088%2ffinding-nearby-cities-using-google-api%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            SQL update select statement

            'app-layout' is not a known element: how to share Component with different Modules