Note that there are some explanatory texts on larger screens.

plurals
  1. POGet specific Value between Javascript Function by NSRegularExpression?
    text
    copied!<p><strong>I am creating a project for learning purpose:</strong></p> <p><strong>FOR INFO :</strong> I have not used <code>UIWebView</code></p> <p>In my project I got <code>HTML</code> data(<em>content</em>) from server. This data contains all information about places(<em>from google map</em>). For getting specific data from <code>HTML</code> content I need to parse <code>HTML</code>. I parse <code>HTML</code> using <a href="https://github.com/topfunky/hpple" rel="nofollow"><code>Hpple</code></a>. And I could successfully parse HTML to get specific data (<em>Such as name,address…etc</em>), but when <strong>I need to parse latitude and longitude</strong> from <code>HTML</code> content, I am confused about how to get latitude and longitude of places, because those are part of <code>Javascript</code>. I mean these latitude and longitude data are available in <code>Javascript's</code> functions.</p> <p><strong>Javascript content that I got from Server:</strong> <em>(My limitation is that, I can only put piece of javascript code bacause this code is very very long)</em></p> <pre><code>function() { window.gHomeVPage= { title:'Hostel, Bhavnagar, Gujarat, India - Google Maps',url:'/?q\\x3dHostel,+Bhavnagar,+Gujarat,+India\\x26hq\\x3dHostel,\\x26hnear\\x3dBhavnagar,+Gujarat,+India\\x26t\\x3dm\\x26ie\\x3dUTF8',urlViewport:false,ei:'jp8tUb3uNK2ciAeQroGACw', form:{ selected:'q', q:{q:'Hostel, Bhavnagar, Gujarat, India',what:'Hostel,',near:'Bhavnagar, Gujarat, India'},d:{saddr:'',daddr:'',dfaddr:'Bhavnagar, Gujarat, India'},geocode:''}, query:{type:'l'},viewport:{center:{lat:21.757528,lng:72.15303},span:{lat:0.034314,lng:0.039956},zoom:14,mapType:'m',source:0},modules:['','strr','pphover','act_s','appiw','rst'], overlays:{sxcar:false, markers: [{id:'A',cid:'7569356420090555589',latlng:{lat:21.747064,lng:72.169678},image:'http://maps.gstatic.com/intl/en_ALL/mapfiles/markers2/circleA.png',sprite:{width:20,height:34,top:0,image:'http://maps.gstatic.com/mapfiles/markers2/red_circle_markers_A_J2.png'},icon_id:'A',ext:{width:20,height:34,shadow:'http://maps.gstatic.com/intl/en_ALL/mapfiles/circle-shadow45.png',shadow_width:37,shadow_height:34,mask:false},drg:true,laddr:'Shree Sahajanand Girls Ptc Hostel, Ghogha Road, Bhavnagar, Gujarat 364001, India',geocode:'CfYWJFjKQj0mFXjVSwEdzjhNBCmN5-3pPlpfOTHF7NFVj8ELaQ',sxti:'Shree Sahajanand Girls Ptc Hostel',name:'Shree Sahajanand Girls Ptc Hostel',infoWindow:{title:'Shree Sahajanand Girls Ptc \\x3cb\\x3eHostel\\x3c/b\\x3e',addressLines:['Ghogha Road','Bhavnagar, Gujarat 364001, India'],phones:[{number:'0278 2562529'}],basics:'\\x3cdiv transclude\\x3d\\x22iw\\x22\\x3e\\x3c/div\\x3e',moreInfo:'more info',place_url:'http://maps.google.com/local_url?dq\\x3dHostel,+Bhavnagar,+Gujarat,+India\\x26q\\x3dhttps://plus.google.com/106028699675431268945/about%3Fhl%3Den\\x26s\\x3dANYYN7mCKtIBT1JPxwi6G2b9gVDdCuVyyA',zrvOk:true,loginUrl:'https://www.google.com/accounts/ServiceLogin?service\\x3dlocal\\x26hl\\x3den\\x26nui\\x3d1\\x26continue\\x3dhttp://maps.google.com/maps/place%3Fcid%3D7569356420090555589%26q%3DHostel,%2BBhavnagar,%2BGujarat,%2BIndia%26t%3Dm%26cd%3D1%26cad%3Dsrc:ppwrev%26ei%3Djp8tUb3uNK2ciAeQroGACw%26action%3Dopenratings',lbcurl:'http://www.google.com/local/add/choice?hl\\x3den\\x26gl\\x3dIN\\x26latlng\\x3d7569356420090555589\\x26q\\x3dHostel,\\x26near\\x3dBhavnagar,+Gujarat,+India',link_jsaction:''},ss:{edit:true,detailseditable:true,deleted:false,rapenabled:true,mmenabled:true},b_s:2,approx:true,elms:[4,1,6,2,12,1,9,1,5,2,11] } } </code></pre> <p>Here in above code I want to get value of <strong><code>lat:</code></strong> and <strong><code>lon:</code></strong> from <code>latlng:{lat:21.747064,lng:72.169678}</code></p> <p>For getting it from javascript, <strong>I googled</strong> and found that I need to use <a href="https://developer.apple.com/library/mac/#documentation/Foundation/Reference/NSRegularExpression_Class/Reference/Reference.html" rel="nofollow"><code>NSRegularExpression</code></a> class for get specific matches(<em>of Data</em>) form content.</p> <p>Then I tried with following code </p> <pre><code>NSError *error = NULL; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(?-imsx:latlng:)" options:NSRegularExpressionCaseInsensitive error:&amp;error]; NSArray *arrayOfAllMatches = [regex matchesInString:locationStr options:0 range:NSMakeRange(0, [locationStr length])]; for (NSTextCheckingResult *match in arrayOfAllMatches) { NSString* substringForMatch = [locationStr substringWithRange:match.range]; NSLog(@"%@",substringForMatch); } </code></pre> <p>I got output in console like this:</p> <pre><code>2013-02-28 11:35:25.051 MapExample[949:13d03] latlng: 2013-02-28 11:35:25.766 MapExample[949:13d03] latlng: 2013-02-28 11:35:26.208 MapExample[949:13d03] latlng: 2013-02-28 11:35:26.799 MapExample[949:13d03] latlng: 2013-02-28 11:35:27.303 MapExample[949:13d03] latlng: 2013-02-28 11:35:27.722 MapExample[949:13d03] latlng: </code></pre> <p>How can I get content of searched node from <code>NSRegularExpression</code> ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload