# Problems Attempting to Combine MVC Mapping with Geocoding

**URL:** <https://community.thinkgeo.com/t/problems-attempting-to-combine-mvc-mapping-with-geocoding/4180>\
**Category:** MVC\
**Created:** [May 5, 2014, 2:05pm UTC](https://community.thinkgeo.com/t/problems-attempting-to-combine-mvc-mapping-with-geocoding/4180 "2014-05-05T14:05:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael12](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/m/ec9cab/32.png) [@Michael12](https://community.thinkgeo.com/u/Michael12)\
**Post date:** [May 5, 2014, 2:05pm UTC](https://community.thinkgeo.com/t/problems-attempting-to-combine-mvc-mapping-with-geocoding/4180/1 "2014-05-05T14:05:04Z")

</div>

I&nbsp;am&nbsp;in&nbsp;the&nbsp;process&nbsp;of&nbsp;evaluating&nbsp;the&nbsp;Map&nbsp;Suite&nbsp;MVC&nbsp;Edition&nbsp;and&nbsp;Geocoder.&nbsp;&nbsp;I&nbsp;am&nbsp;attempting&nbsp;to&nbsp;recreate&nbsp;the&nbsp;quick&nbsp;start&nbsp;demo&nbsp;for&nbsp;the&nbsp;Geocoder&nbsp;located&nbsp;[here](http://wiki.thinkgeo.com/wiki/Map_Suite_Geocoder_Quick_Start_Guide)&nbsp;using&nbsp;an&nbsp;MVC&nbsp;Web&nbsp;Project&nbsp;with&nbsp;an&nbsp;OpenStreetMap&nbsp;layer&nbsp;as&nbsp;the&nbsp;base&nbsp;layer.&nbsp;&nbsp;I&nbsp;have&nbsp;encountered&nbsp;a&nbsp;problem&nbsp;in&nbsp;that&nbsp;the&nbsp;marker&nbsp;for&nbsp;1701&nbsp;Thome&nbsp;Ave&nbsp;is&nbsp;being&nbsp;placed&nbsp;in&nbsp;Lake&nbsp;Michigan.&nbsp;I&nbsp;believe&nbsp;the&nbsp;geocoding&nbsp;to&nbsp;be&nbsp;working&nbsp;correctly,&nbsp;but&nbsp;something&nbsp;is&nbsp;obviously&nbsp;wrong&nbsp;when&nbsp;I&nbsp;go&nbsp;to&nbsp;place&nbsp;the&nbsp;marker&nbsp;on&nbsp;the&nbsp;map.&nbsp;I&nbsp;have&nbsp;several&nbsp;questions.  
  
  
  
1.&nbsp;First,&nbsp;the&nbsp;marker&nbsp;on&nbsp;the&nbsp;map&nbsp;is&nbsp;not&nbsp;drawn&nbsp;until&nbsp;I&nbsp;either&nbsp;zoom&nbsp;in&nbsp;or&nbsp;out.&nbsp;Why&nbsp;is&nbsp;this?&nbsp;I&nbsp;am&nbsp;making&nbsp;an&nbsp;explicit&nbsp;call&nbsp;to&nbsp;the&nbsp;redrawLayer&nbsp;function&nbsp;of&nbsp;the&nbsp;map.&nbsp;The&nbsp;following&nbsp;.js&nbsp;are&nbsp;attached&nbsp;to&nbsp;a&nbsp;button&nbsp;to&nbsp;initiate&nbsp;the&nbsp;geocoding&nbsp;process&nbsp;serverside&nbsp;and&nbsp;update&nbsp;the&nbsp;page&nbsp;with&nbsp;the&nbsp;response:

> `function`&nbsp;`Geocode() {`  
> `    ``var`&nbsp;`address = $(``"#idAddressBox"``).val();`  
> `    ``var`&nbsp;`param = { address: address };`  
> `    ``Map.ajaxCallAction(``‘Home’``, ``‘Geocode’``, param, callback);`  
> `};`  
> &nbsp;  
> `function`&nbsp;`callback(result) {`  
> `    ``var`&nbsp;`resultString = result.get_responseData();`  
> `    ``if`&nbsp;`(resultString != ``""``) {`  
> `        ``$(``"#idResultsArea"``).val(resultString);`  
> `    ``}`  
> `    ``Map.redrawLayer(``"MarkerLayer"``);`  
> `};`

  
  
  
2.&nbsp;When&nbsp;an&nbsp;InMemoryFeatureLayer&nbsp;is&nbsp;created,&nbsp;what&nbsp;is&nbsp;the&nbsp;default&nbsp;projection&nbsp;used?&nbsp;I&nbsp;think&nbsp;I&nbsp;read&nbsp;somewhere&nbsp;in&nbsp;the&nbsp;forums&nbsp;that&nbsp;an&nbsp;InMemoryFeatureLayer&nbsp;uses&nbsp;the&nbsp;same&nbsp;projection&nbsp;as&nbsp;the&nbsp;base&nbsp;overlay,&nbsp;though&nbsp;I&nbsp;may&nbsp;be&nbsp;remembering&nbsp;incorrectly.  
  
  
  
3.&nbsp;The&nbsp;result&nbsp;from&nbsp;geocoding&nbsp;returns&nbsp;a&nbsp;centroid&nbsp;point&nbsp;defined:&nbsp;[CentroidPoint,&nbsp;POINT(-87.671919&nbsp;41.9956200000006)]&nbsp;which&nbsp;is&nbsp;used&nbsp;to&nbsp;place&nbsp;the&nbsp;marker&nbsp;on&nbsp;the&nbsp;map&nbsp;using&nbsp;an&nbsp;InMemoryFeatureLayer.&nbsp;&nbsp;The&nbsp;coordinates&nbsp;are&nbsp;obviously&nbsp;geodetic.&nbsp;Currently&nbsp;I&nbsp;am&nbsp;using&nbsp;a&nbsp;custom&nbsp;function&nbsp;to&nbsp;convert&nbsp;the&nbsp;returned&nbsp;geodetic&nbsp;coordinates&nbsp;into&nbsp;spherical&nbsp;mercator,&nbsp;and&nbsp;then&nbsp;using&nbsp;those&nbsp;to&nbsp;create&nbsp;a&nbsp;PointShape&nbsp;which&nbsp;I&nbsp;then&nbsp;use&nbsp;to&nbsp;add&nbsp;a&nbsp;new&nbsp;feature&nbsp;into&nbsp;the&nbsp;InMemoryFeatureLayer.&nbsp;Is&nbsp;there&nbsp;no&nbsp;functionality&nbsp;to&nbsp;do&nbsp;this&nbsp;built&nbsp;in,&nbsp;or&nbsp;does&nbsp;there&nbsp;exist&nbsp;a&nbsp;means&nbsp;of&nbsp;doing&nbsp;this&nbsp;without&nbsp;having&nbsp;to&nbsp;manually&nbsp;convert&nbsp;the&nbsp;coordinates?&nbsp;&nbsp;The&nbsp;normal&nbsp;means&nbsp;of&nbsp;handling&nbsp;projection&nbsp;changes&nbsp;using&nbsp;the&nbsp;Proj4Projection&nbsp;class,&nbsp;say&nbsp;between&nbsp;OSM&nbsp;and&nbsp;a&nbsp;NAD83&nbsp;shapefile&nbsp;would&nbsp;seem&nbsp;not&nbsp;to&nbsp;apply&nbsp;in&nbsp;this&nbsp;situation.

---

<div class="post-metadata">

**Author:** ![Troy](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/85f322/32.png) [@Troy](https://community.thinkgeo.com/u/Troy)\
**Post date:** [May 6, 2014, 1:01am UTC](https://community.thinkgeo.com/t/problems-attempting-to-combine-mvc-mapping-with-geocoding/4180/2 "2014-05-06T01:01:35Z")

</div>

Hi&nbsp;Michael,  
  
  
  
Thanks&nbsp;for&nbsp;evaluating&nbsp;our&nbsp;products!  
  
As&nbsp;for&nbsp;your&nbsp;questions,&nbsp;I&nbsp;think&nbsp;&nbsp;it&nbsp;is&nbsp;a&nbsp;projection&nbsp;issue.&nbsp;Here&nbsp;is&nbsp;my&nbsp;understandings&nbsp;and&nbsp;answers&nbsp;for&nbsp;them,&nbsp;please&nbsp;let&nbsp;me&nbsp;know&nbsp;if&nbsp;you&nbsp;have&nbsp;any&nbsp;questions.  
  
  
  
In&nbsp;your&nbsp;case,&nbsp;as&nbsp;you&nbsp;are&nbsp;using&nbsp;OpenStreetMap&nbsp;as&nbsp;the&nbsp;base&nbsp;layer,&nbsp;the&nbsp;default&nbsp;projection&nbsp;should&nbsp;be&nbsp;under&nbsp;Mercator&nbsp;projection&nbsp;with&nbsp;meter(same&nbsp;layer&nbsp;like&nbsp;Bing,Google&nbsp;layers).&nbsp;But&nbsp;the&nbsp;geocoder&nbsp;result&nbsp;centroid&nbsp;is&nbsp;under&nbsp;EPSG&nbsp;4326&nbsp;with&nbsp;decimal&nbsp;degree.&nbsp;So,&nbsp;we&nbsp;should&nbsp;do&nbsp;a&nbsp;projection&nbsp;converter&nbsp;for&nbsp;the&nbsp;centroid&nbsp;marker.&nbsp;There&nbsp;are&nbsp;two&nbsp;ways&nbsp;to&nbsp;do&nbsp;the&nbsp;converter:&nbsp;  
  
1.&nbsp;Convert&nbsp;the&nbsp;marker&nbsp;coordinates&nbsp;directly&nbsp;and&nbsp;then&nbsp;add&nbsp;the&nbsp;projected&nbsp;marker&nbsp;into&nbsp;the&nbsp;layer.  
  
2.&nbsp;Apply&nbsp;the&nbsp;projection&nbsp;converter&nbsp;on&nbsp;the&nbsp;layer&nbsp;and&nbsp;then&nbsp;add&nbsp;the&nbsp;original&nbsp;marker&nbsp;into&nbsp;the&nbsp;layer.&nbsp;In&nbsp;this&nbsp;way,&nbsp;all&nbsp;the&nbsp;markers&nbsp;will&nbsp;do&nbsp;a&nbsp;conversion&nbsp;with&nbsp;the&nbsp;converter&nbsp;before&nbsp;placing&nbsp;the&nbsp;marker&nbsp;on&nbsp;the&nbsp;map.  
  
Here&nbsp;are&nbsp;some&nbsp;codes:

> `PointShape centroid = ``new`&nbsp;`PointShape(-55,45); ``// decimal degree`  
> &nbsp;  
> `Proj4Projection proj4 = ``new`&nbsp;`Proj4Projection();`  
> `proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);`  
> `proj4.ExternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(900913);`  
> `proj4.Open();`  
> &nbsp;  
> `// option 1`  
> `PointShape projectedCentroid = proj4.ConvertToExternalProjection(centroid) ``as`&nbsp;`PointShape;`  
> `inMemoryLayer.InternalFeatures.Add(``new`&nbsp;`Feature(projectedCentroid));`  
> `// option 2`  
> `inMemoryLayer.FeatureSource.Projection = proj4;`  
> `inMemoryLayer.InternalFeatures.Add(``new`&nbsp;`Feature(centroid));`

  
For&nbsp;"&nbsp;When&nbsp;an&nbsp;InMemoryFeatureLayer&nbsp;is&nbsp;created,&nbsp;what&nbsp;is&nbsp;the&nbsp;default&nbsp;projection&nbsp;used?&nbsp;",&nbsp;yes,&nbsp;we&nbsp;can&nbsp;think&nbsp;it&nbsp;is&nbsp;the&nbsp;same&nbsp;with&nbsp;the&nbsp;base&nbsp;layer.  
  
  
  
Hope&nbsp;my&nbsp;explain&nbsp;is&nbsp;clear,&nbsp;but&nbsp;if&nbsp;you&nbsp;still&nbsp;have&nbsp;the&nbsp;issue,&nbsp;it&nbsp;is&nbsp;better&nbsp;you&nbsp;can&nbsp;attache&nbsp;any&nbsp;codes&nbsp;or&nbsp;sample.  
  
Thanks,  
  
Troy
