javascript - get latitude and longitudefrom city name using HTML,js in bing map -


i need latitude , longitude city name using bing map. here code.

 function geocode() {     //create bing maps rest services request geocode address provided user     var geocoderequest = "http://dev.virtualearth.net/rest/v1/locations/"        + "colombo"        + "?output=json"        //set callback function        + "&jsonp=getlocationcoordinates"        + "&key=ai5r7k1jy95bfrdbov9ppvobqyicnne3bapi7pczgda-l30cjbphelnk8xqmyckl";     //submit request      makeservicerequest(geocoderequest);  }  function makeservicerequest(request) {      var script = document.createelement("script");     script.setattribute("type", "text/javascript");     script.setattribute("src", request);     document.body.appendchild(script);     getlocationcoordinates(); }   function getlocationcoordinates(geocoderesponse) {     if(geocoderesponse==null) document.getelementbyid("txt").innertext = "this null";     if (geocoderesponse &&            geocoderesponse.resourcesets &&            geocoderesponse.resourcesets.length > 0 &&            geocoderesponse.resourcesets[0].resources &&            geocoderesponse.resourcesets[0].resources.length > 0) {      setloc(geocoderesponse.resourcesets[0].resources[0].geocodepoints.coordinates[0], geocoderesponse.resourcesets[0].resources[0].geocodepoints.coordinates[1], 10);     }     else {//the location not geocoded         var md = new windows.ui.popups.messagedialog("the location not geocoded");         md.showasync();     } } 

but in here never called function getlocationcoordinates(geocoderesponse). how can make call it.?

probably because running local context. create iframe , add code in resulting html file.

i've wrapped code in namespace. way can define function called rather sticking functions in global namespace. note commented out direct call of function, not needed.

create /pages/map/map.html, map.js, map.css (in other words, create /pages/map , right click on , select add new item , choose 'page' type named map)

in map.js include following after 'use strict', or include in javascript file. it's you.

     winjs.namespace.define("locationservices", {         getlocationcoordinates: function (geocoderesponse) {             if (geocoderesponse == null) document.getelementbyid("txt").innertext = "this null";             if (geocoderesponse &&                    geocoderesponse.resourcesets &&                    geocoderesponse.resourcesets.length > 0 &&                    geocoderesponse.resourcesets[0].resources &&                    geocoderesponse.resourcesets[0].resources.length > 0) {                  setloc(geocoderesponse.resourcesets[0].resources[0].geocodepoints.coordinates[0], geocoderesponse.resourcesets[0].resources[0].geocodepoints.coordinates[1], 10);             }             else {//the location not geocoded                 var md = new windows.ui.popups.messagedialog("the location not geocoded");                 md.showasync();             }         },         geocode: function () {             //create bing maps rest services request geocode address provided user             var geocoderequest = "http://dev.virtualearth.net/rest/v1/locations/"                + "colombo"                + "?output=json"                //set callback function                + "&jsonp=locationservices.getlocationcoordinates"                + "&key=ai5r7k1jy95bfrdbov9ppvobqyicnne3bapi7pczgda-l30cjbphelnk8xqmyckl";             //submit request              this.makeservicerequest(geocoderequest);          },         makeservicerequest: function (request) {              var script = document.createelement("script");             script.setattribute("type", "text/javascript");             script.setattribute("src", request);             document.body.appendchild(script);             // getlocationcoordinates();         }     });  

in turn load map.html (which includes reference map.js , has input id='txt')

<iframe src="ms-appx-web:///pages/map/map.html"></iframe>

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -