0

I have a json response in this format please look at this.I want to get lat and long values for every address.

{
    "message":"success",
    "data":
    {
        "docs":
        [
            {
                "_id":"573d8eca67c7f172cc88387e",
                "user":
                {
                    "phone":"8510932519)/+",
                    "image":"",
                    "name":"Niraj@%"
                },
                "distance":18825,
                "bookingNumber":"42aopy2dyry8",
                "bookingType":0,
                "paymentMode":"Card",
                "tip":0,
                "estimatedFare":51.1,
                "estimatedDuration":"2364",
                "created":"2016-05-18T14:49:31.231Z",
                "stop2":
                {
                    "address":"Malviya Nagar, New Delhi, Delhi 110017, India",
                    "location":[28.533519700000003,77.21088569999999]
                },
                "stop1":
                {
                    "address":"Ansari Nagar East, New Delhi, Delhi 110029, India",
                    "location":
                    [
                        28.566540099999997,
                        77.2098409
                    ]
                },
                "destination":
                {
                    "address":"Saket, New Delhi, Delhi 110017, India",
                    "location":
                    [
                        28.524578699999996,
                        77.206615
                    ]
                },
                "currentLocation":
                {
                    "address":"26, Ashok MargJ Block, Pocket J, Sector 18",
                    "location":
                    [
                        28.568437,
                        77.32404
                    ]
                }
            }
        ],
        "total":1,
        "limit":8,
        "page":":1",
        "pages":1 
    }
}

i need to get lat and long for every address. i am using this code for get the address, but how will i get lat and long for 0 and 1 index in location array?

  dictionary = [[NSJSONSerialization JSONObjectWithData:data options:0 error:nil]objectForKey:@"data"];


  NSArray *IDArray = [dictionary objectForKey:@"docs"];
  for (NSDictionary *Dict in IDArray)
  {

      NSMutableDictionary *temp = [NSMutableDictionary new];
      [temp setObject:[Dict objectForKey:@"_id"] forKey:@"_id"];

      NSString *booknumber = [Dict objectForKey:@"bookingNumber"];
      if([booknumber length] != 0)
          [temp setObject:booknumber forKey:@"bookingNumber"];

      NSMutableDictionary *stp1 = [Dict objectForKey:@"stop1"];

      if ([[stp1 allKeys] containsObject:@"address"]) {

          [temp setObject:[stp1 objectForKey:@"address"] forKey:@"address"];
      }

      NSMutableDictionary *stp2 = [Dict objectForKey:@"stop2"];

      if ([[stp2 allKeys] containsObject:@"address"]) {

          [temp setObject:[stp2 objectForKey:@"address"] forKey:@"address1"];
      }



      NSMutableDictionary *currentloc = [Dict objectForKey:@"currentLocation"];

      if ([[currentloc allKeys] containsObject:@"address"]) {

          [temp setObject:[currentloc objectForKey:@"address"] forKey:@"address1"];

      }
6
  • first of all add proper tags ... iOS .. but is it in swift or Obj-C ... other thing is post your code ... Commented May 24, 2016 at 11:24
  • @Marco sir this is in dictionary format, all the response Commented May 24, 2016 at 11:35
  • Thanks for your response bro Commented May 24, 2016 at 11:48
  • sir i need to get lat and long from location array for every address so that i convert lat and long into places and show on map Commented May 24, 2016 at 11:49
  • i am able to get address name but how will i get lat and long for 0 and 1 index in location array Commented May 24, 2016 at 11:53

1 Answer 1

1

try this

NSMutableDictionary *stp1 = [Dict objectForKey:@"stop1"];

  if ([[stp1 allKeys] containsObject:@"address"]) {

      [temp setObject:[stp1 objectForKey:@"address"] forKey:@"address"];

      // take one Temp array for fetch lat and long

     NSArray *tempstp1 =  [stp1 objectForKey:@"location"];
       [temp setObject:[tempstp1 objectAtIndex:0] forKey:@"latitude"];
       [temp setObject:[tempstp1 objectAtIndex:1] forKey:@"longitude"];
  }

  NSMutableDictionary *stp2 = [Dict objectForKey:@"stop2"];

  if ([[stp2 allKeys] containsObject:@"address"]) {

      [temp setObject:[stp2 objectForKey:@"address"] forKey:@"address"];

        // take one Temp array for fetch lat and long

     NSArray *tempstp2 =  [stp2 objectForKey:@"location"];
       [temp setObject:[tempstp2 objectAtIndex:0] forKey:@"latitude"];
       [temp setObject:[tempstp2 objectAtIndex:1] forKey:@"longitude"];
  }
Sign up to request clarification or add additional context in comments.

6 Comments

ohh bro sorry i was forgot to add array agian, thanks its working for me
@sandeeptomar - haha ha ,already you mentioned the answer also bro, (i am able to get address name but how will i get lat and long for 0 and 1 index in location array)
yes sir its my mistake haha, thanks for your support sir
@sandeeptomar - now you have a exp guy , try yourself if it is wrong dont feel , day by day automatically you learn easily , any way have a happy day ,
I guess Telling how to Fish is better than Serving a Fish to someone.
|

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.