IPhone के लिए Google मानचित्र हाल ही में सामने आया, और एसडीके के लिए एपीआई कुंजी प्राप्त करना आसान नहीं है। हो सकता है कि यहां बताई गई विधि कईयों के लिए उपयोगी हो, लेकिन फिर भी मैं लिखूंगा।
मुख्य विचार जावास्क्रिप्ट एपीआई का उपयोग करना है। उदाहरण के लिए, मैंने दिशा एपीआई को चुना।
परिणाम प्रदर्शित करने के लिए "से" और "कहां" और "वेब व्यू" दर्ज करने के लिए 2 फ़ील्ड बनाए जाते हैं।

मैंने WebView में एक अलग फ़ाइल में प्रदर्शन के लिए टेम्पलेट सेट किया है, इसे "map.html" कहा जाता है। यहाँ इसकी सामग्री हैं:
<!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map_canvas { height: 100% } </style> <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true"></script> <script type="text/javascript"> var directionsDisplay; var directionsService = new google.maps.DirectionsService(); var map; function initialize() { directionsDisplay = new google.maps.DirectionsRenderer(); var chicago = new google.maps.LatLng(41.850033, -87.6500523); var mapOptions = { zoom:7, mapTypeId: google.maps.MapTypeId.ROADMAP, center: chicago } map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); directionsDisplay.setMap(map); calcRoute('chicago, il', 'st louis, mo'); } function calcRoute(start, end) { var request = { origin:start, destination:end, travelMode: google.maps.TravelMode.DRIVING }; directionsService.route(request, function(result, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(result); } }); } </script> </head> <body onload="initialize()"> <div id="map_canvas" style="width:100%; height:100%"></div> </body> </html>
तब सब कुछ बहुत सरल है। "ViewDidLoad" में createMap को मैप को इनिशियलाइज़ करने के लिए कहा जाता है। कोड "createMap":
- (void) createMap:(id)sender{ [map loadHTMLString:[self readFile:[[NSBundle mainBundle] pathForResource:@"map" ofType:@"html"]] baseURL:[NSURL URLWithString:@"google.com"]]; }
और एक हैंडलर "फील्ड" को बदलने के लिए तैयार है:
- (void) findOnMap:(id)sender{ [map stringByEvaluatingJavaScriptFromString: [[[[@"calcRoute('" stringByAppendingString: from.text ] stringByAppendingString: @"', '"] stringByAppendingString: to.text] stringByAppendingString: @"');" ] ]; }
इस प्रकार, आप GoogleMaps पर किसी भी एपीआई अनुरोध को निष्पादित कर सकते हैं। यह, निश्चित रूप से, एक अस्थायी तरीका है जब तक कि Google अनुरोध पर तुरंत एसडीके को चाबियाँ जारी करना शुरू नहीं करता है।
यहाँ यह कैसा दिखता है:
