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
























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















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
























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













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















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















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 14:47









Mihai Chelaru

2,10071022




2,10071022










asked Nov 19 at 9:54









kulveer singh Mrar

41




41












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


















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
















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




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












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
    });


    }
    });














    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 Nov 19 at 10:49

























        answered Nov 19 at 10:43









        Mohammad Umair

        1,7481620




        1,7481620






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            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

            Paul Cézanne

            UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

            Angular material date-picker (MatDatepicker) auto completes the date on focus out