0
 class GetRouteDriver(APIView):
    authentication_classes = (TokenAuthentication,)    
    permission_classes = (IsAuthenticated,)
    def get(self, request, username, origin, destination):  
        origin_lat, origin_lng = origin.split(',')
        destination_lat, destination_lng = destination.split(',')
        url = 'https://maps.googleapis.com/maps/api/directions/json?origin=' + origin + '&destination=' + destination + '&key'+ GOOGLE_KEY 
        request_data = urllib2.urlopen(url)
        serialized_data = request_data.read()
        id = '1'
        ride = json.loads(serialized_data)

        return Response( ride, status=status.HTTP_200_OK )

i want to add the ID to the ride retrived from Google Maps API

and with the code from above i Got this and this is what i want. enter image description here

if i Concatenate The ID i get this enter image description here

this is the code with the concatenation

class GetRouteDriver(APIView):
    authentication_classes = (TokenAuthentication,)    
    permission_classes = (IsAuthenticated,)
    def get(self, request, username, origin, destination):  
        origin_lat, origin_lng = origin.split(',')
        destination_lat, destination_lng = destination.split(',')
        url = 'https://maps.googleapis.com/maps/api/directions/json?origin=' + origin + '&destination=' + destination + '&key'+ GOOGLE_KEY 
        request_data = urllib2.urlopen(url)
        #serialized_data = request_data.read()
        serialized_data = json.dumps({'ride_id': 1, 'route': request_data.read()})
        ride = json.loads(serialized_data)
        return Response( ride, status=status.HTTP_200_OK )
1
  • What have you tried so far? What's not working? Are you getting errors? Help us help you. Commented Nov 23, 2015 at 23:45

1 Answer 1

2

i just made this i load the json from the google Response before make jason.dumps like in this code .

class GetRouteDriver(APIView):
    authentication_classes = (TokenAuthentication,)    
    permission_classes = (IsAuthenticated,)
    def get(self, request, username, origin, destination):  
        origin_lat, origin_lng = origin.split(',')
        destination_lat, destination_lng = destination.split(',')

        url = 'https://maps.googleapis.com/maps/api/directions/json?origin=' + origin + '&destination=' + destination + '&key'+ GOOGLE_KEY 
        request_data = urllib2.urlopen(url)
        #serialized_data = request_data.read()

        serialized_data = json.dumps( { 'ride_id': 1 , 'route': json.loads(request_data.read()) })
        route = json.loads(serialized_data)
        return Response( route, status=status.HTTP_200_OK )

And now i get what i want .

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.